Menu

gitpiper

addMultipleListeners javascript Code Snippet in 2024

browsereventintermediate

Last Updated: 7 October 2024

Adds multiple event listeners with the same handler to an element.

  • Use Array.prototype.forEach() and EventTarget.addEventListener() to add multiple event listeners with an assigned callback function to an element.
const addMultipleListeners = (el, types, listener, options, useCapture) => { types.forEach(type => el.addEventListener(type, listener, options, useCapture) ); };
addMultipleListeners( document.querySelector('.my-element'), ['click', 'mousedown'], () => { console.log('hello!') } );

javascript snippet similar to addMultipleListeners For You in October 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️