Home › Forums › JavaScript › onclick=”document.getElementById” Question
- This topic is empty.
-
AuthorPosts
-
August 4, 2011 at 6:33 am #33785
Mitchell
MemberHi,
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?
Cheers.
August 4, 2011 at 9:05 am #84475Mottie
MemberHi 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.
August 4, 2011 at 9:26 am #84476Mitchell
MemberHi 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.
August 4, 2011 at 9:51 am #84477Mottie
MemberOh I see… well it’s essentially the same thing except use the document blah blah LOL (demo):
August 4, 2011 at 10:07 am #84479Mitchell
MemberThankyou 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!!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.