$("#archive").click(function(event){
/*do something*/
});
$('#archive2').unbind('click',event);
i have this click function that I unbind. however, i want to bind it again when i click a certain button.
$("#archive").bind("click",event);
im using this code to bind again, however it doesn't seem to work. any suggestions or workarounds?
As of jQuery 1.7 you should use on and off for all your event handler binding:
Why not have a boolean value and an
if
statement in the event handler?Try this:
You have to keep a reference to the function (instead of passing an anonymous function):
Not sure what is
event
in your case, but if it is theevent
object passed to the event handler then it does not make sense to pass it tounbind
andbind
.You need to provide a handler to the function so you can bind/unbind from it. (Also allows you to bind/unbind specific events handlers within the same event:
(used from http://api.jquery.com/unbind/ )