I have a group of about 40 pictures on a website page of past scholarship recipients. I would like to add the picSize and picReturn functions to each picture as mouse event function or event listener without writing separate variables using getElementById...I would rather iterate through the array of pics using getElementsByClassName and assign the event to every pic.
Is there a way to apply an event listener to an entire class of elements?
let studentPic = document.getElementById("recipient-image1");
const picSize = () => {
studentPic.style.height = "342px";
studentPic.style.width = "300px";
studentPic.style.left = '20%';
studentPic.style.zIndex = '1';
}
const picReturn = () => {
studentPic.style.height = "";
studentPic.style.width = "";
studentPic.style.left = '';
studentPic.style.zIndex = '';
}
studentPic.addEventListener('mouseover', picSize);
studentPic.onmouseout = () => {
picReturn()
}