I am trying to dynamically change a picture when I click on it, via the addEventListener. I have the pictures in the documents.images array. I already have a function written to switch the images. The problem I am having is binding this in the event that I click on an image.
This is what I tried
document.images[i]src.addEventListener("click", MakeMove, false);
You want to add the event to the actual image:
but older browsers don’t support these DOM Level 2 event handlers, so, assuming these images don’t have to have multiple click handlers, consider doing
EDIT
To pass a parameter to
MakeMove, you’d setonclickto an anonymous function that callsMakeMovewith whatever values you need:From your original code:
isn’t valid, and
would be a string, to which you obviously cannot add an event handler.