How can I can this image gallery to change the big image to the thumbnail image? I can't seem to get it to work. I need to get the src attribute of the thumbnail into the value for the big src attribute's value.
<html>
<head>
<title>title</title>
<link rel="stylesheet" type="text/css" href="CSSChloe.css">
</head>
<body id = "bodyc">
<div id = "space1">
</div>
<div id = "header">
<div class="image">
<img src = "Banner.png" alt= " " width="257" height="43" />
<h4> text</h4>
</div>
</div>
<div id = "space2"> </div>
<div id= "menuBack">
<div id= "menu1"><a href="index.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
<div id= "menu1"><a href="about.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
<div id= "select"><a href="photo.html" style="text-decoration:none;">
<img src = "back.png" alt = " " width = "257" height = "48" style = "position: absolute; left: -14px; top: -5px;" />
<p id = "menu2" style = "position: absolute; margin-top: 2%;">Photo Gallery</p></a>
</div>
<div id= "menu1"><a href="price.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
<div id= "menu1"><a href="testimontials.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
<div id= "menu1"><a href="contact.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
<div id= "menu3"><img src ="photographylogo.png" width = "150" height = "125" /></div>
</div>
<div id = "space3"> </div>
<div id= "content">
<div style = "width: 60%; height: 100%; float: left;">
<img id = "big" src ="test1.png" width = "400" height = "350" style = "margin-top: 5%; margin-left: 8%;" />
</div>
<div style = "width: 35%; height: 100%; overflow: auto; float:right;">
<img id = "thumb1" onclick = "thumbFunc('test2.png');" src = "test2.png" width = "150" height = "100" />
<img id = "thumb2" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb3" src = " " width = "150" height = "100" />
<img id = "thumb4" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb5" src = " " width = "150" height = "100" />
<img id = "thumb6" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb7" src = " " width = "150" height = "100" />
<img id = "thumb8" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb9" src = " " width = "150" height = "100" />
<img id = "thumb10" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb11" src = " " width = "150" height = "100" />
<img id = "thumb12" src = " " width = "150" height = "100" />
<br/>
<img id = "thumb13" src = " " width = "150" height = "100" />
<img id = "thumb14" src = " " width = "150" height = "100" />
</div>
</div>
<script>
function thumbFunc(a)
{
document.getElementById("big").setAttribute(src, a);
}
</script>
</body>
</html>
First, change the way you call your function on your inline on-click:
onclick="thumbFunc('test2.png');"
to this, so you don't have to put the image path again:
onclick="thumbFunc(this.src)"
Then, change your javascript:
document.getElementById("big").setAttribute(src, a);
to this (if you prefer simpler way):
document.getElementById("big").src = a;
or if you want to still stick with the setAttribute
method, don't forget to enclose the attribute(src) with the "
symbol:
document.getElementById("big").setAttribute("src", a);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.