I'm trying to create a bunch of images inside js and add Event Listeners to each of them so that they trigger function when clicked.
I use this function to create images.
function image(fileName) {
const img = new Image(100, 100);
img.src = `images/${fileName}`;
return img;
}
When I try to add an event listener with
image.addEventListener(...)
It compiles but doesn't work when drawing the images later.
I have also tried adding an id to the image and using getElementById()
to add the listener, it doesn't compile with the event listener reading null.
Any suggestions?