Hi, I am new to javascript and just tried out a few examples provided on w3 schools javascript section. One of them was the Button Animationexample. I did a slight modification to this example. Here's what i am trying to achieve:- onMouseOver of the anchor tag, i am replacing the image with a string(using innerHTML of the anchor tag). While doing this, i maintain the image object in a global variable - onMouseOut of the anchor tag, i am trying to restore back the image by using the contents of the global variable.I am able to do the replace the image with the string in onMouseOver, however onMouseOut, i am not able to restore it back.Here's the code:
<html><head><script type="text/javascript">var myvfunction mouseOver(){myv=document.getElementById("mya").innerHTML//alert("Before replacing innerHTML is: " + myv)document.getElementById("mya").innerHTML="Hi"//alert("After replacing, obj is: " + myv)}function mouseOut(){//alert("Before assigning in moveout, obj is: " + myv)document.getElementById("mya").innerHTML=myv}</script></head><body><a id="mya" href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver()"onmouseout="mouseOut()"><img border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b1" width="26" height="26" /></a></body></html>
I have commented out the alerts. Please uncomment them if required. Whats baffling me is that at the end of the mouseOver() method, i print the contents of the global variabl 'myv' which correctly points to the image object. But, on entering the mouseOut() method, when i print the contents of the same, the contents have surprising changed to the string 'hi'.Any idea, whats wrong here?