Jump to content

document.getElementById("").src


jmurph333
 Share

Recommended Posts

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?

Edited by jmurph333
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...