I have a silly query maybe but I can not figure out how to do it, I want to do this same but with Javascript pure:
$('.clase').click(function(){
$(this).toggleClass('activo');
});
What I can not do with pure Javascript is to apply the event to all the elements that have that class, because when I want to add an addEventListener to an element that I select according to the class.
I get an error because it asks me to add the index number of that element, but what I want is to apply it, not to a particular element, but to all those that have that kind.
javascript
var boxProducto = document.getElementsByClassName("box-producto");
for(i=0;i<boxProducto.length;i++){
boxProducto[i].addEventListener("click",function(){
alert("hola");
});
}
Why does not it work for me?