Answers for "does js allow u add multiple elements to event listener"

11

add event listener to multiple element in JS

document.querySelectorAll('.some-class').forEach(item => {
  item.addEventListener('click', event => {
    //handle click
  })
})
Posted by: Guest on August-07-2020
0

addeventlistener javascript multiple functions

const invokeMe = () => console.log('I live here outside the scope');
const alsoInvokeMe = () => console.log('I also live outside the scope'); 

element.addEventListener('event',() => {    
     invokeMe();
     alsoInvokeMe();    
});
Posted by: Guest on April-07-2021

Code answers related to "does js allow u add multiple elements to event listener"

Code answers related to "Javascript"

Browse Popular Code Answers by Language