0

I want to know how to update a href link with javascript using an image. I have a image which has to update a href which displays a lightbox. Could someone please tell me know to do this.

Edited by scarcella: n/a

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by scarcella
0

an image update it? Do you mean if someone clicks on the image? What href will it be updating?

<script type="text/javascript">
function someFunc() {
  (update HREF - code depends on what you are wanting)
}
</script>
<img src="" onclick="someFunc();" />
0

Basically, when i click on an image it should update 1 href link (updating the link and the image it containes.

Ill show you a code of that is should look like after the image has been clicked.

<a href="/images/lightbox/test2.jpg" rel="lightbox"><img src="/images/test2.jpg"></a>

<!-- CLICKED IMAGE -->
<img src="/images/thumb/text.jpg" onclick"update_link();">

Hope thant helped..

Thanks for the help guys,
Marais

Edited by scarcella: n/a

1

I am still not sure what you are ultimately wanting. Does the clicked image get an href applied to it after it is clicked and the image itself changes?...or does clicking the image change an existing href and image?...or???

You can change attributes:

function update_link() {
  document.getElementById("myLink").setAttribute("href", "/images/lightbox/test2.jpg");
}
0

Thank you, SolidSolutions this really helped..

I am still not sure what you are ultimately wanting. Does the clicked image get an href applied to it after it is clicked and the image itself changes?...or does clicking the image change an existing href and image?...or???

You can change attributes:

function update_link() {
  document.getElementById("myLink").setAttribute("href", "/images/lightbox/test2.jpg");
}

SOLVED! :D

Thanks,
Marais

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.