callback – the previously attached [[mdn>Web/JavaScript/Reference/Global_Objects/Function|function]] to remove again (required).
Returns:
The [[mdn>Web/API/HTMLElement|HTMLElement]] it was called on, thus allowing for command chaining.
Notes
* This is just a simple wrapper for the JavaScript [[mdn>Web/API/EventTarget/removeEventListener|.removeEventListener]] method, which also allows to use more specific options.
* The function reference needs to be the same as was previously attached using [[toolbox:event:on:index|.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 function
…
foo.off('click', callback); // removes the function again.
===== See also =====
* [[toolbox:event:on:index|.on]]
* [[toolbox:event:once:index|.once]]
===== More information =====
* [[mdn>Web/JavaScript/Reference/Global_Objects/Function|Function]] on MDN.
* [[mdn>Web/API/EventTarget/removeEventListener|EventTarget: removeEventListener() method]] on MDN.