Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

addeventlistener on multiple div with class

const boxes = document.querySelectorAll('.box');

boxes.forEach(box => {
  box.addEventListener('click', function handleClick(event) {
    console.log('box clicked', event);

    box.setAttribute('style', 'background-color: yellow;');
  });
});
Source by bobbyhadz.com #
 
PREVIOUS NEXT
Tagged: #addeventlistener #multiple #div #class
ADD COMMENT
Topic
Name
7+7 =