Events API

evt.remove()

async

Removes an event listener from the target.

  • An event listener can be removed from a Window, Document, Element, array of elements, NodeList, or HTMLCollection.
    If no target is specified, automatically detects the correct target.
  • Accepts the type of event to remove, provided as a case-sensitive string, as the first argument.
    Accepts the same function (or object with a handleEvent method) that was specified when adding the event listener, as the second argument.
    Accepts an optional third argument, the same as the one set when adding the event listener.
  • Removing an event listener will be successful if it has the same target, function, and options as when the event listener was added.
  • It is not necessary to wait for the method to be executed using await if not needed.
Example:
// Removes an event listener from the Document.
document.evt.remove('click', (e) => {});

// Removes an event listener from the Window.
window.evt.remove('scroll', (e) => {});

// Removes an event listener from the <div> element.
$('div').evt.remove('click', (e) => {});

// Removes an event listener from all <div> elements.
$('div ?').evt.remove('click', (e) => {});

// Automatically detects the correct target and removes the event listener, in this case, the Document.
evt.remove('click', (e) => {});

// Automatically detects the correct target and removes the event listener, in this case, the Window.
evt.remove('scroll', (e) => {});
evt.remove('resize', (e) => {});

// Removes an event listener with the specified options.
evt.remove('click', (e) => {}, true);
evt.remove('click', (e) => {}, {capture: true});
$('div').evt.remove('click', (e) => {}, {
   capture: false,
   once: true,
   passive: false
});

// Removes an event listener for built-in events.
evt.remove('mutation', (e) => {});
$('div').evt.remove('mutation', (e) => {});
$('div').evt.remove('resize', (e) => {});
$('div').evt.remove('visible', (e) => {});
$('div').evt.remove('invisible', (e) => {});

// Waits for the event listener to be removed from the target.
await evt.remove('click', (e) => {});