Answers for "how to add eventlister to multiple variable"

0

how to add eventlister to multiple variable

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

how to add eventlister to multiple variable

[document.querySelector('.a-class'), document.querySelector('.another-class')].forEach(item => {
  item.addEventListener('click', event => {
    //handle click
  })
})
Posted by: Guest on April-02-2021

Code answers related to "how to add eventlister to multiple variable"

Browse Popular Code Answers by Language