Reputation: 63369
I found sometimes I hook up 2 functions to the buttun, using .click(function(){}), is it possible for me to remove the prior attached function before I hook up new one?
Upvotes: 4
Views: 1203
Reputation: 1296
There are 2 ways:
function foo(){
//do stuff
}
function bar(){
//do more
}
jQ.click(foo).click(bar);
jQ.unbind(foo);
or
jQ.bind('click.foo', function(){
//do stuff
});
jQ.click(function(){
//do more
});
jQ.unbind('.foo');
Upvotes: 0
Reputation: 17965
Not using an anonymous delegate like that. You can .unbind a named function though.
UPDATE
Actually you can call .unbind() with no arguments to remove all handlers or .unbind('click') to remove all handlers for a particular event.
Upvotes: 8