javascript - Issue in js onmouseover to change pictures. -
i use code make onmouseover change pictures. in ie works, in firefox shows wrong, problem? , can add onmouseout function return first picture me? thanks.
<script type="text/javascript"> function changeimage(rel){ document.getelementbyid("image").src=rel; } </script> <img src="img1.jpg" id="image" /> <a onmouseover="changeimage('img1.jpg')" rel="img1.jpg">img1</a> <a onmouseover="changeimage('img2.jpg')" rel="img2.jpg">img2</a> <a onmouseover="changeimage('img3.jpg')" rel="img3.jpg">img3</a>
you can use:
<script type="text/javascript"> function changeimage(rel) { var img = document.getelementbyid("image"); img.setattribute("orig", img.src); img.src=rel; } function setoriginal() { var img = document.getelementbyid("image"); img.src = img.getattribute("orig"); } </script> <img src="img1" id="image" /> <a onmouseover="changeimage('img1')" onmouseout="setoriginal()" rel="img1">img1</a> <a onmouseover="changeimage('img2')" onmouseout="setoriginal()" rel="img2">img2</a> <a onmouseover="changeimage('img3')" onmouseout="setoriginal()" rel="img3">img3</a>
to return original image. tested on firefox(3.6.12) , working
Comments
Post a Comment