removeEventListenerAll

Detaches an event listener from all the provided targets.

  • Use Array.prototype.forEach() and EventTarget.removeEventListener() to detach the provided listener for the given event type from all targets.
const removeEventListenerAll = (
  targets,
  type,
  listener,
  options,
  useCapture
) => {
  targets.forEach(target =>
    target.removeEventListener(type, listener, options, useCapture)
  );
};
const linkListener = () => console.log('Clicked a link');
document.querySelector('a').addEventListener('click', linkListener);
removeEventListenerAll(document.querySelectorAll('a'), 'click', linkListener);