JavaScript: How to change image on mouseover with JavaScript

2
May 6th, 2009

Want to make a dynamic menu for your website or just make the image change on mouseover ? I have written a script that does that extremely simple and it’s only a few lines long. Of course you could make it a bit more complex, if you need too, but it works just great as is on all new browsers, from IE4 and above.

Follow this steps to use this script on your website:

  1. You need 2 images, the one that appears all the time and the one that appears on mouse over. The images must be .jpg or .gif.
  2. Copy the code below between the and in your website and change the images location after img1.src and img2.src:

Tags: , , , , , , ,