Forum Moderators: open

Message Too Old, No Replies

hides all layers except the one

hide all layers except one ... In NS4+

         

pvz77

12:16 pm on Nov 5, 2003 (gmt 0)



The following script (found on [webmasterworld.com...] ) hides all layers except the one you specify (as show in the onclick-events further down). My question is: How can I make this work in NS4+ as well as in IE? Currently, the script works like a charm in IE, but in NS the layers are all shown despite clicking the links... Hope someone can help! Thanks/Per, Sweden

<html>
<head>
<SCRIPT type="text/javascript">
states=new Array()
states[0]="txt"
states[1]="img"
states[2]="vid"

function hideallexcept(elm) {
for (var i = 0; i < states.length; i++) {
var layer = document.getElementById(states[i]);
if (elm!= states[i]) {
layer.style.display = "none";
}
else {
layer.style.display = "block";
}
}
}
</SCRIPT>
</head>
<body>

<DIV id="txt" style="position: absolute; left: 75px; top: 40px; height: 400px; width: 450px; z-index: 2; visibility: visible;">txt-window </div>
<DIV id="img" style="position: absolute; left: 75px; top: 40px; height: 400px; width: 450px; z-index: 2; visibility: visible;">img-window </div>
<DIV id="vid" style="position: absolute; left: 75px; top: 40px; height: 400px; width: 450px; z-index: 2; visibility: visible;">vid-window </div>

<A HREF="#" onclick="hideallexcept('txt');">click to view text</A><BR>
<A HREF="#" onclick="hideallexcept('img');">click to view img</A><BR>
<A HREF="#" onclick="hideallexcept('vid');">click to view vid</A><BR>

</body>
</html>

DrDoc

7:10 pm on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Välkommen till Webmaster World! ;)

Well, NN4 doesn't understand document.getElementById. It uses document.layers instead. Now, the other problem is that NN4 doesn't handle display:none correctly. There are times when an element with display:none cannot be "brought back", no matter what you set display to.

DrDoc

7:11 pm on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since the divs are absolutely positioned, you should just toggle the visibility property instead :)