I'm working on a website, and the pictures page I'm trying to create has 1 big picture, with smaller thumbnails underneath. I have a javascript function in the head:
function loadThumbnail(divID){
document.getElementById("mainPicture").src = document.getElementById(divID).src;
document.getElementById("mainPicture").alt = document.getElementById(divId).alt;
document.getElementById("caption").innerHTML = document.getElementById(divId).alt;
}
The parameter divID is a misleading title, it's actually the ID of the img element that holds the thumbnail. The function is called whenever the user clicks a thumbnail. The .src bit works, but I can't get the function to change the caption to the picture. Any idea why?
Edit: Here's the HTML
<img id="mainPicture" src="images/food/chickenAndCheeseFries1.png" width="420" height="313" alt="Chicken Tenders and Cheese Fries">
<p id="caption">Chicken tenders and cheese fries</p>
<div onClick="loadThumbnail('t1')" id="thumbnail1" class="thumbnail">
<div id="thumbnailPic1" class="thumbnailPic">
<img id="t1" src="images/food/buffaloAndHotWings1.png" width="105" height="80" alt="Sweet Chilly and Buffalo Wings">
</div>
</div>
.getAttribute("alt")instead of.alt?divIDand at the other you're usingdivIdwhich isundefinedthus resulting in an error.