JavaScript: How to change image on mouseover with JavaScript
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:
- 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.
- Copy the code below between the and in your website and change the images location after img1.src and img2.src:












So many small bugs in that little pice of code… here is a “working” edition:
if (document.images) {
image1 = new Image; image2 = new Image;
image1.src = ”;
image2.src = ”;
}
Hmm… doesn’t seem to allow posting of code