Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Best way to remove an event handler in jQuery?

At that point when the user taps the picture, they get a little popup to add a few notes to the data.

My concern is that when a user enters a zero into the text box, I need to disable the information picture's occasion controller. I have attempted the accompanying however without much of any result.

$('#myimage').click(function { return false; });
by

2 Answers

aashaykumar
If you want to respond to an event just one time, the following syntax should be really helpful:

$('.myLink').bind('click', function() {
//do some things

$(this).unbind('click', arguments.callee); //unbind just this handler
});

Using arguments.callee, we can ensure that the one specific anonymous-function handler is removed, and thus, have a single time handler for a given event. Hope this helps others.
RoliMishra
$('#myimage:not(.disabled)').live('click', myclickevent);
$('#mydisablebutton').click( function () { $('#myimage').addClass('disabled'); });


What will happen with this code is that when you click #mydisablebutton, it will add the class disabled to the #myimage element. This will make it so that the selector no longer matches the element and the event will not be fired until the 'disabled' class is removed making the .live() selector valid again.

This has other benefits by adding styling based on that class as well.

Login / Signup to Answer the Question.