Forum Moderators: open
The code below works in IE6 (hurrah and wonders).
According to all I have read it should also work in NS6 or 7/Firefox - but no it doesn't.
Not supporting older browsers on this site.
Subbing document.GetElementById(me).style for me.style
works in IE and not in NS etc.
Avoiding visibility property due to it consuming inline space. besides this should work for either-right?
What am I not seeing?
Relevant CSS
#newslist { font-size: 12px; background-color: #ffffff; display: none; position:relative; z-index: 6; left: 50px; width: 150px; border: solid 2px #b54905 }
Relevant js
function chgdsplay(me)
{
if (me.style.display=="none"){
me.style.display="block";}
else {
me.style.display="none";}
}
Relevant Html
<div onclick="chgdsplay(newslist)" id="newsbox">
News
</div><!-- end of newsbox -->
<div onmouseout="chgdsplay(newslist)" id="newslist">
<a id="link1" href="http://www.link1.com" onmouseover="chgdsplay(newslist)">link1</a><br>
<div onmouseout="chgdsplay(newslist)" id="newslist">
<a id="link2" href="http://www.link2.com" onmouseover="chgdsplay(newslist)">link2</a><br>
</div><!-- end of newslist-->
Thanks a almost newbie
The ObjID.style shortcut method actually works in IE6/7 (strict mode)as does the Document.GetElementByID(ObjID).style method.
But neither works in NS, which is what I am looking to solve. I have this code listed as cross browser but it is possible I am wrong. If so How would you code for NS?
..but I did make a mistake in the code. It's supposed to reference the style object directly (why not go straight for the object we want). I forgot to...
[pre]
function chgdsplay(me)
{
var style = document.getElementById(me)[red].style[/red];
style.display = style.display == "none"? "block" : "none";
}
[/pre]
The only time you need worry about browser implementations is when choosing global variable names, because you run the risk of conflict with window methods and properties, some of which are added by browser makers (window.opera for instance).
The variable is question here is local, so there are no worries.