jmurph333 Posted April 19, 2010 Share Posted April 19, 2010 When I was first starting JavaScript I read "Head First JavaScript" (Great Book!) and it used a specific method so that when a button or image is clicked, it can adjust the source of the image. <head><script type="text/javascript">function changeImage() {document.getElementById("iRock").src = "iRock_Happy.png";}</script></head><body><img src="iRock.png" id= "iRock" onclick="changeImage()"></body> I used almost the exact same code as this except with my pictures, although it does not work.Any thoughts? Link to comment Share on other sites More sharing options...
Ingolme Posted April 19, 2010 Share Posted April 19, 2010 The function name is wrong:function changeImage() {onclick="changeImg()" Link to comment Share on other sites More sharing options...
jmurph333 Posted April 19, 2010 Author Share Posted April 19, 2010 That was my typo....I'll change it. Link to comment Share on other sites More sharing options...
Ingolme Posted April 19, 2010 Share Posted April 19, 2010 The only other problem I can see is that the image might be a little slow loading. click on it and wait a few seconds to see if it changes.Make sure the image exists and that the file path is correct too. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.