The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript onclick=”document.getElementById” Question

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #33785


    At the moment, I have a bit of code that when clicked, it changes the source of an image above, like below.

    onclick="document.getElementById('image').src='new image path'"

    This image has a link around it, and I want to change the path of that link at the same time, so baically I want a way of doing something like:

    onclick="document.getElementById('image').src='new image path'" & document.getElementById('link').src='new link path'"

    But obviously that above isn’t correct. Can anyone give me a hand?



    Hi Mitchell!

    It would be better to just use “this” instead of “document.get… blah blah blah”. Here is a demo of how to do it

    But notice that I added another onclick inside the link to ignore the click (which isn’t really what you wanted) because when you click on the image it will open a new page with that image immediately after it changes the image. Remove the onclick in the link to see what I’m talking about – I added a red border around the image so you can see when it changes.


    Hi Mottie, Thanks for your reply :)

    I didn’t really explain it very well. I have got a big image with 2 thumbnails beneath. when clicking one of the thumbnails, it should change the src of the main image and the link around it. the main image itself has not got a link on it, but is part of a zoom plugin.

    This is it online, hopefully it helps to understand what I need a bit better.

    The link around the img is the source of the image that is displayed on the zoom, and you can see at the moment this doesn’t change.

    Thanks again.


    Oh I see… well it’s essentially the same thing except use the document blah blah LOL (demo):


    Thankyou very much :)

    I tried to get this to work, but it didn’t. I did a bit of digging and found that the link I was trying to change didn’t actually make a difference to the big image.

    I went back to the plugin website and they have got a thumbnail extension. Played around with a bit of the code they provide and I got it to work!

    Thanks again for your help!!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.