steva
asked on
Rollover JavaScript not working in Safari and Chrome
I have a page that displays a thumbnail image when you roll over a link.
The JavaScript routines for rollove rand rollout are simply:
<script type="text/javascript" language="javascript">
function showImage(image) {
image.style.visibility="vi sible";
}
function hideImage(image) {
image.style.visibility="hi dden";
}
</script>
And the HTML is:
<img id="sib_1_tn" class="thumb" src="images/Siblings/sib_1 _tn.jpg" />
<a href="sib_1.php" onmouseover="showImage(sib _1_tn)" onmouseout="hideImage(sib_ 1_tn)">Sib ling 1 </a>
=================
This works fine in IE and Firefox but neither Chrome nor Safari display the thumbnail image when you roll over the link. Does anyone run an idea what the problem might be?
Thanks for any suggestions.
Steve
The JavaScript routines for rollove rand rollout are simply:
<script type="text/javascript" language="javascript">
function showImage(image) {
image.style.visibility="vi
}
function hideImage(image) {
image.style.visibility="hi
}
</script>
And the HTML is:
<img id="sib_1_tn" class="thumb" src="images/Siblings/sib_1
<a href="sib_1.php" onmouseover="showImage(sib
=================
This works fine in IE and Firefox but neither Chrome nor Safari display the thumbnail image when you roll over the link. Does anyone run an idea what the problem might be?
Thanks for any suggestions.
Steve
<img id="sib_1_tn" class="thumb" src="images/Siblings/sib_1_tn.jpg" />
<a href="sib_1.php" onmouseover="showImage('sib_1_tn')" onmouseout="hideImage('sib_1_tn')">Sibling 1 </a>
an update to the function in this case : http://jsfiddle.net/QXJWn/
function showImage(image) {
document.getElementById(image).style.visibility="visible";
}
function hideImage(image) {
document.getElementById(image).style.visibility="hidden";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Leakim. The basic problem was that I was just using the passed in ID to access the DOM element (image.style.visibility="v isible") instead of going through getElementById(). For some reason Firefox and IE let you get away with this, but not Safari and Chrome.
Thanks. I gave you the points.
Steve
Thanks. I gave you the points.
Steve
Hi Steve,
What's up? Yes, you used shorcut references for your fields.
It's a good pratice to use :
document.getElementsByName ("NAME_ATT RIBUTE")[0 ]
or :
document.getElementById("I D_ATTRIBUT E")
please note the << [0] >> on the first one and the << s >> after element
You can have multiple fields with the same name in a page ( [0] for the first one, [1] for the second and so on )
ID should/MUST be unique so there's no getElementsById
Thanks for the points
Best Regards
What's up? Yes, you used shorcut references for your fields.
It's a good pratice to use :
document.getElementsByName
or :
document.getElementById("I
please note the << [0] >> on the first one and the << s >> after element
You can have multiple fields with the same name in a page ( [0] for the first one, [1] for the second and so on )
ID should/MUST be unique so there's no getElementsById
Thanks for the points
Best Regards
ASKER
Got it! Thanks.
(I'm fine. When I'm not doing web pages for people I'm working my "software" through Microsoft's "Certified For" program to give it credibility. I hope all is well with you.).
(I'm fine. When I'm not doing web pages for people I'm working my "software" through Microsoft's "Certified For" program to give it credibility. I hope all is well with you.).
very nice, good luck, don't forget the fun
onmouseover="showImage('si