I am trying to set a style event for a multiple images tags and I can't: the error is in the anonymous function of the event when I put into a loop to make the effect individually and for all galleries in the document with images[i]
.
Why ? : Uncaught TypeError: Cannot set property 'style' of undefined at HTMLImageElement.<anonymous>
images = document.querySelectorAll(".gallery img");
for (var i=0; i<images.length; i++){
images[i].addEventListener('mouseout', function(){ images[i].style=" transform: scale(.8)" });
images[i].addEventListener('mouseover', function(){ images[i].style=" transform: scale(1.2)" });
}
<div class="gallery">
<img src="https://picsum.photos/300/180">
<img src="https://picsum.photos/300/180">
<img src="https://picsum.photos/300/180">
</div>