how to add eventlister to multiple variable code example
Example 1: how to add eventlister to multiple variable
[document.querySelector('.a-class'), document.querySelector('.another-class')].forEach(item => {
item.addEventListener('click', event => {
//handle click
})
})
Example 2: how to add eventlister to multiple variable
document.querySelectorAll('.some-class').forEach(item => {
item.addEventListener('click', event => {
//handle click
})
})