I am completely new to this community (and JavaScript is also new for me), so I apologize in advance for asking some very basic questions. I have an HTML page with various images, all of which share a common class. After using getElementsByClassName, I obtain an array. My goal is to attach an event listener to each cell in the array by utilizing the .map() function.
Here is my current attempt:
window.onload = function(){
var allImgs = document.getElementsByClassName("pft");
var newImgs = allImgs.map(
function(arrayCell){
return arrayCell.addEventListener("mouseover, functionName");
}
);
};
Unfortunately, I keep receiving the error "allImgs.map is not a function" even when I modify the inner function to remove the event listener.
In another version of this code, I simply loop through the array cells within window.onload and add the event listener to each one, which works perfectly fine. So, why isn't the .map() function working here? Is it possible that it cannot be used within window.onload?