I was trying to make an image to change on mouse over. This piece of code works for IE but not for the other browsers like chrome, opera, safari, etc. Any ideas?
<a href="#" onmouseover="document.myimage1.src='img/login_button_22.jpg';"
onmouseout="document.myimage1.src='img/login_button_11.jpg';">
<img src="img/login_button_11.jpg" name="myimage1" /> </a>
You should be using a ID, not a NAME, and using
document.getElementByIdto select the element.IMG elements, not being FORM elements, should not be able to take on a NAME property, but Microsoft managed to screw this up.
Also, it’s much easier and cleaner to use a CSS background and a
:hoverdeclaration and skip doing this using JavaScript completely.Here’s how:
HTML:
CSS (adjust dimensions accordingly):