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.

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();" />

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

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");
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.