You should use querySelectorAll instead of querySelector, then loop over all list items:
var listItems = document.querySelectorAll('li');
for(var i = 0; i < listItems.length; i++){
listItems[i].addEventListener('click', function(event) {
this.classList.toggle('clicked');
});
}
Top comments (0)