0

How can I get classList from the element I click, it just gives me classList for last one in the list.

var boxes = document.querySelectorAll(".sqr")


for(i=0; i<boxes.length; i++){
    var box = boxes[i]   
        box.addEventListener("click", function(){
            if (box.classList.contains("sqr2")){
                console.log(box.classList)
            }
            else{
                console.log(box.classList)
            }   
        })
}
LukaZmaj
  • 13
  • 4

0 Answers0