As i searched for the solution of a problem i have right now, i found this thread: jQuery: more than one handler for same event. Now i wonder if it is possible to remove just a single one of these handlers?
Go to the objects tab, view the Document object (don't click on edit) and scroll down to Event Handlers. Select the one to delete and press delete.
You can assign as many handlers as you want to an event using addEventListener(). addEventListener() works in any web browser that supports DOM Level 2.
Using off() Method: It is used to remove event handlers attached with the on() method.
The removeEventListener() method removes an event handler from an element.
It is possible, if you don't use anonymous callbacks:
var $elt = $(...); function clickHandler1(event){...} function clickHandler2(event){...} // bind both $elt.click(clickHandler1); $elt.click(clickHandler2); // unbind just the first $elt.unbind('click', clickHandler1);
A wild Demo appeared!
See also: .unbind()
docs.
Actually, you can do it using anonymous callbacks via event namespacing:
$elt.bind('click.handler1', function(event) { alert('click handler 1'); }); $elt.unbind('click.handler1');
See modified demo here.
And here for more information.
This was added in jQuery 1.4.3, which actually came out more than 4 months before the question was asked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With