Jump to content

document.getElementById("").src


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...