Forum Moderators: open

Message Too Old, No Replies

Popup layer

onclick hide/show layer with javascript

         

Jared_NZ

1:00 am on Mar 31, 2004 (gmt 0)

10+ Year Member



Hi I have this code


function showLayer(lyr)
{
if (document.all)
{
document.all[lyr].style.visibility = "visible";
}

if (document.layers)
{
document.layers[lyr].visibility = "show";
}
}

function hideLayer(lyr)
{
if (document.all)
{
document.all[lyr].style.visibility = "hidden";
}
if (document.layers)
{
document.layers[lyr].visibility = "hide";
}
}

which works perfectly well in IE6.

but I'm trying to get it oging in mozilla/firebird/firefox and it just won't go? I can't understand... I must be using wrong functions or something.

Can someone please shed some light on this for me?

Cheers

Purple Martin

1:46 am on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're doing it with document.all which works in IE and with document.layers which works in Netscape 4. You also need to use document.getElementById which works in all modern browsers.

Jared_NZ

12:19 am on Apr 1, 2004 (gmt 0)

10+ Year Member



Thanks mate, I got it.

here is the code if anyone else wants it.. I had difficulty finding a simple piece of code to do this.


function showLayer(lyr)
{
if (document.all)
{
document.all[lyr].style.visibility = "visible";
}

if (document.layers)
{
document.layers[lyr].visibility = "show";
}

if (document.getElementById)
{
document.getElementById(lyr).style.visibility = "visible";
}
}

function hideLayer(lyr)
{
if (document.all)
{
document.all[lyr].style.visibility = "hidden";
}

if (document.layers)
{
document.layers[lyr].visibility = "hide";
}

if (document.getElementById)
{
document.getElementById(lyr).style.visibility = "hidden";
}
}