back to Overview

$.off()

Removes the given event handler.
Web module only.

Syntax

$.off(handler)

Parameters

handler
the handler to unregister, as given to on(). It must be a handler that has previously been registered using on(). If the handler is not registered as event handler, the function does nothing.

Description

Removes the given event handler. The call will be ignored if the given handler has not been registered using on(). If the handler has been registered for more than one element or event, it will be removed from all instances.

Please note that you can not unregister event handlers registered using onOver() or onChange().

Example

Adds a handler to an element:

function myEventHandler() {
   this.style.backgroundColor = 'red';        // 'this' contains the element that caused the event
}
$('#myElement').on('click', myEventHandler);  // add event handler

window.setInterval(function() {               // after 5s, remove event handler
   $.off(myEventHandler);
}, 5000);

See also..

  • on() registers an event handler.

Comments

comments powered by Disqus

back to Overview

Functions