Click to See Complete Forum and Search --> : Help: onMouse


johnnyG
05-27-2003, 08:48 AM
I used this code for a webpage:

<img src="pil1.gif" name="pil1" width="10" height="5" alt="" /> <a href="links.html" onmouseover="document.pil1.src='pil.gif'; document.pil2.src='pil2.gif'; return true" onmouseout="document.pil1.src='pil1.gif';document.pil2.src='pil3.gif'; return true">Links</a>&nbsp;<img src="pil3.gif" name="pil2" width="10" height="5" alt="" />

And this code works great. But when I changed my homepage to XHTML, I can't use NAME in img-tag, instead I use ID. But then I got a javascript error and it doesn't work:

<img src="pil1.gif" id="pil1" width="10" height="5" alt="" /> <a href="links.html" onmouseover="document.pil1.src='pil.gif'; document.pil2.src='pil2.gif'; return true" onmouseout="document.pil1.src='pil1.gif';document.pil2.src='pil3.gif'; return true">Links</a>&nbsp;<img src="pil3.gif" id="pil2" width="10" height="5" alt="" />

Please help me to get this onMouseOver to work so its valid XHTML? Why doesn't it work?

khalidali63
05-27-2003, 08:55 AM
there are couple of ways you can do that in your current setup

replace these lines
document.pil1

with

this.parentNode.src.......

or document.getElementById('pil1').src

johnnyG
05-27-2003, 09:07 AM
It works!

Thank you so much!

khalidali63
05-27-2003, 10:45 AM
:D
Great..