PDA

View Full Version : Javascript for layer visibility not working in firefox


wingedbunny
04-12-2007, 02:36 AM
I'm trying to have invisible layers of text show up as an onClick event, but the code on found doesnt seem to work in firefox and safari, is there any other ways of doing this or modifying this so it works in most browsers?

heres the code: (its from http://www.irt.org/script/225.htm )

<STYLE type="text/css"><!--
#about { visibility: hidden; }
#text2 { visibility: hidden; }
--></STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.layers)
var doc = 'document.', vis = '.visibility';
if (document.all)
var doc = 'document.all.', vis = '.style.visibility';

function show(object) {
if (document.layers || document.all)
eval(doc + object + vis + ' = "visible"');
}

function hide(object) {
if (document.layers || document.all)
eval(doc + object + vis + ' = "hidden"');
}

function hideAll() {
hide('about');
hide('text2');
}

//-->
</SCRIPT>

<link href="style.css" rel="stylesheet" type="text/css" />
</HEAD>

<BODY>

<DIV ID="about">
text goes here~ meow <3
</DIV>

<a href="#" onclick="hideAll();show('about');"> clicky here</a>
<DIV ID="text2">
text block two!
</DIV>

glenngv
04-12-2007, 05:35 AM
Your code doesn't work because it's only for IE and the old Netscape 4 browsers. Here's the modern version.
function showHide(objectId, visibility) {
document.getElementById(objectId).style.visibility = visibility;
}

function hideAll() {
showHide('about', 'hidden');
showHide('text2', 'hidden');
}

<a href="#" onclick="hideAll();showHide('about','visible');return false;"> clicky here</a>