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);
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️