-1

I have a function that I want to run on page load or refresh, but then I want to change it or remove it and add another function that is similar, but only runs on click. I'm trying:

$(document).ready(function () {

$(window).('load.First', function() {
 alert('load function');
});

$(window).unbind('.First');

$(window).bind('click', function() {
 alert('second function');
});

});
Travis Skweres
  • 173
  • 1
  • 1
  • 6
  • You code syntactically is wrong and why are you trying to unbind the load event which is fired once? What are you trying to achieve? Do you want to register a handler for each click on document? – Ram Dec 09 '12 at 05:33

1 Answers1

0

Your unbind looks like it should be inside the the first bind function, otherwise it would run straight away and immediately unbind the bound function. One way of doing this would be to add/remove a class and control the actions based on the class the link has at any time.

$(document).on('click', '.first', function(){
    $(this)
        .removeClass('first')
        .addClass('second')
        .text('second');
});

Demo: http://jsfiddle.net/MLX4Z/

qooplmao
  • 17,622
  • 2
  • 44
  • 69