Table of Contents

<HTMLElement>.off()

Removes a previously attached event callback function from an HTMLElement.

Usage:
HTMLElement = Element.off(callback)
Member of:
HTMLElement
Parameter:
callback – the previously attached function to remove again (required).
Returns:
The HTMLElement it was called on, thus allowing for command chaining.
Notes
  • This is just a simple wrapper for the JavaScript .removeEventListener method, which also allows to use more specific options.
  • The function reference needs to be the same as was previously attached using .on, or any of its shortcut functions. This implies that such a reference must be available, which by extension means that anonymous functions can not be detached.

Examples

let callback = function(e) {
  console.log(e);
}
let foo document.getElementById('foo');
foo.on('click', callback);   // attaches the callback functionfoo.off('click', callback);   // removes the function again.

See also

More information