Change Image 2 | JavaScriptSource

Change Image 2

JavaScriptSource Staff Dec 26, 2007


Use this script to change an image, using the setAttribute function. You can use different events to change the image, e.g., onClick, or onMouseOver. The script can also be adapted to other uses.

[Click the picture above to see the mountains]


  • Created by: Yakor
  • Posted: December 26, 2007

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: changeImage2.js


Paste this code into the HEAD section of your HTML document.


Paste this code into the BODY section of your HTML document

Leave a Response


In order to better help you, you'll need to post your question [a href=""]over on the forums[/a].

Lee Jun 26, 2008

i think this code may not work in ruby onrail context.i implimented it .it does not work.can any body help me while clicking on the image another image will come and viceversa.

bishnu das Feb 27, 2008

You can either change it (see out tutorials section for help), or use another script.

Lee Underwood Jan 29, 2008

Thanks Yakor for this script this very eyecatching script.keep it up. we all need good coder like you *BEST OF LUCK FOR YOUR WORK*

Sankalp khanna Jan 9, 2008

I think this is good but I would like the image to change randomly every time the page loads. There's no information for here about how to customize the script for people that don't know javascript.

Ian Jan 2, 2008