Deregistering Event Handlers
After registering an event handler with bind() (or with any of the simpler event
registration methods) you can deregister it with unbind() to prevent it from being triggered by
future events. (Note that unbind()
only deregisters event handlers registered with bind() and related jQuery methods. It does not
deregister handlers passed to addEventListener() or the IE method attachEvent(), and it does not remove handlers
defined by element attributes such as onclick and onmouseover.) With no arguments, unbind() deregisters all event handlers (for
all event types) for all elements in the jQuery object:
// Remove all jQuery event handlers from all elements!
$('*').unbind();
With one string argument, all handlers for the named event type (or types, if the string names more than one) are unbound from all elements in the jQuery object:
// Unbind all mouseover and mouseout handlers
// of all <a> tags
$('a').unbind("mouseover mouseout");
This is a heavy-handed approach and should not be used in modular
code because someone might also be using other modules that register
their own handlers for the same event types on the same elements. If
your module registered event handlers using namespaces, however, you can
use this one-argument version of unbind() to deregister only the handlers in
your namespace:
// Unbind all mouseover and mouseout handlers // in the "myMod" namespace $('a').unbind("mouseover.myMod mouseout.myMod"); // Unbind handlers for any event in the myMod ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access