Alex Rivera | Logout

Is it possible to remove one specific event handler from an event with multiple handlers?

Asked 2011-02-27T22:00:02.150
49

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?

Edit
Report

1 Answer

84

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.

answered 2011-02-27T22:19:38.227

Your Answer