Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
firends,
i hav written following code for changing image source on mouseover event .
its working fine in chrome and mozilla bt not working in IE.
---------------------------------------------------------------------------------------
img src="images/--col---fix-12.png" id="img2" onmouseover="img2.src='images/1234.png';" onmouseout=" img2.src='images/--col---fix-12.png';"
--------------------------------------------------------------------------------------------
please sort it out.
thanx in advance
Posted

1 solution

Define a JS method for mouseover and mouseout. In those methods, reset the source.

Ex:
HTML
<img src="images/--col---fix-12.png" id="img2" onmouseover="SecondImage();" onmouseout="OriginalImage();"> 

JavaScript
function SecondImage()
{
  document.getElementById('img2').src = 'images/1234.png';
}
function OriginalImage()
{
  document.getElementById('img2').src = 'images/--col---fix-12.png';
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Feb-13 16:54pm    
Correct, my 5, but it can be done more elegantly with jQuery.
—SA
Sandeep Mewara 15-Feb-13 0:09am    
Thanks SA. I am with you. No doubt about it - almost all the JS operations can be done more elegantly using jQuery. :)

My answer was based on OP's question that looked like a beginner.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900