"this" refers to th[c], and now look at your image tags:
They don't have href attribute, so your swapFile function fails and terminates script execution. You could add custom attributes to these images:
But images are not anchors, so th[c].href will not give you the value.
Here's the new init function:
function init(){
th=document.getElementById('thumbs').getElementsByTagName('img');
for(c=0;c
I have tested the code locally and it runs.
answered
Jan 19, 2014 at 22:52
SchienSchien
3,7171 gold badge15 silver badges29 bronze badges
answered
Nov 13, 2021 at 7:21
How do you change href link using JavaScript?
Anchor href Property.
Change the destination (URL) of a link: getElementById("myAnchor"). href = "http://www.cnn.com/";.
Get the URL of a link: getElementById("myAnchor"). href;.
Another example of how to get the URL of a link (a relative URL): var x = document. getElementById("myAnchor"). href;.
How do I change a href value?
Answer: Use the jQuery .attr() Method
attr() method to dynamically set or change the value of href attribute of a link or anchor tag. This method can also be used to get the value of any attribute.
How to add href with jQuery?
jQuery: Set href attribute at runtime
Set href attribute at runtime using jquery. JavaScript Code: $(document).ready(function(){ $('#button1').