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


I am running in VISTA. I tried the code as described above, but it did not work in either MSIE9 or Safari5.1.7. So I embedded the code on the page head and it worked in Safari5 and still did not work in MSIE9. I added a line in the head, but it still didn't work. Any ideas what I am doing wrong.

Art Apr 26, 2014

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