On your img tags the onclick function is not wrote correctly should look like
onClick="changeImage()"
Also “changeImage” is not a function you wrote a function called “changePicture” so it should really look like
onClick="changePicture()"
Now in your changePicture function there are a few issues specifically the getElementById function is not being used correctly also you got the name wrong on it you capitalized the ‘D’ at the end which shouldn’t be, I would recommend changing the id on your header tag img from ‘Lilly’ to ‘preview’ since element id’s need to be unique and you’ve already used ‘Lilly’ as an id than replace your script tag with this
I am trying to create an Image Swap with Javascript. Can anyone point me in the direction of where my coding error is in JavaScript? Am I using the getElementByID incorrectly? Any help or direction is much appreciated!
With the image swap I am trying to have it where when the thumbnail picture is clicked on it will take place of
image. Sorry for not clarifying.
Comment posted by the documentation for
There’s a whole range of issues with your code, but I think
Comment posted by Siguza
I also suggest looking up how to open the web developer console for your browser, as that should aid you greatly in debugging.
Comment posted by bleepbloopblop123
Also make sure the src you’re setting them as in the script tag is the correct src for your project I see you using “Skelton_ImageSwap/images/” in your html but in the script you’re setting them as “Skelton_ImageSwap/image/” do you have both an image and images directory in your project
Comment posted by LcSkelt
Thank you for your help! I can definitely see where I had taken a wrong turn now. I think I was trying to make it much more complicated than it needed to be.
Comment posted by bleepbloopblop123
No problem if you need a different solution let me know