.off(type?, fn?)
Available on: InDom, InDomArrayRemoves event listener(s) registered with .on() or its shorthand methods.Parameters:
type {string} (optional) - Event type. If omitted, all listeners are removed.
fn {Function | Function[]} (optional) - Handler(s) returned by .on(). If omitted, all listeners of type are removed.
Returns: {InDom | InDomArray} - this for chainingThrows: TypeError - If type is provided but is not a non-empty string.
RangeError - (InDomArray only) If fn array length does not match collection length.
Error - If the underlying element has been removed
Examples:const divs = $a('.example>div');
divs.onClick(n => {
console.log(n);
/*
this function is visible in DevTools:
#events / click / Set entry / [[TargetFunction]]
*/
});
// a simple logger example
divs.onEnter(n => console.log(`onEnter in:${n.getHtml()}`));
const addOnFns = divs.onEnter(n => n.addClass('on'));
const removeOnFns = divs.onLeave(n => n.removeClass('on'));
// remove addOnFns and removeOnFns but keep the first onEnter logger
divs.off('mouseenter',addOnFns).off('mouseleave',removeOnFns);
// remove every mouseenter handler (including the logger)
divs.off('mouseenter');
// remove every handler of every type (including onClick)
divs.off();Next: getElement »