Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show/hide multiple layers 1

Status
Not open for further replies.

MikeyK

Programmer
Jul 29, 2001
7
AU
I have the following function to show and hide two layers:

I cant get layer B to work, using one function. I think i have to pass the function a generic argument?

Any help would be appreciated. Here is the code:
Code:
<html>
<head>

<SCRIPT language=JavaScript><!--
function showIt(layerA)
{
if(document.layers)
   document.layers[&quot;layerA&quot;].visibility=&quot;visible&quot;;
if(document.all)
   document.all[&quot;layerA&quot;].style.visibility=&quot;visible&quot;;
}

function hideIt(layerA)
{
if(document.layers)
   document.layers[&quot;layerA&quot;].visibility=&quot;hidden&quot;;
if(document.all)
   document.all[&quot;layerA&quot;].style.visibility=&quot;hidden&quot;;
}
// -->
		</SCRIPT>

<STYLE type=text/css>

#layerA {
	BACKGROUND-COLOR: #FFFFFF; LEFT: 10px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden; WIDTH: 300px
}
#layerB {
	BACKGROUND-COLOR: #FFFFFF; LEFT: 10px; POSITION: absolute; TOP: 80px; VISIBILITY: hidden; WIDTH: 300px
}
</STYLE>
		
</head>

<body>

 <A href=&quot;#&quot; onmouseout=hideIt(layerA); onmouseover=showIt(layerA);>Link A</a>    
 <A href=&quot;#&quot; onmouseout=hideIt(layerB); onmouseover=showIt(layerB);>Link B</a>

<DIV class=text id=layerA>AAAAAAAA</DIV>		
<DIV class=text id=layerB>BBBBBBBB</DIV>

</body>
</html>
 
Hiya,

I have adapted your code a bit to serve your needs.

<html>
<head>

<SCRIPT language=JavaScript><!--
function showIt(layerID)
{
if(document.layers)
document.layers[layerID].visibility=&quot;show&quot;;
if(document.all)
document.all[layerID].style.visibility=&quot;visible&quot;;
}

function hideIt(layerID)
{
if(document.layers)
document.layers[layerID].visibility=&quot;hide&quot;;
if(document.all)
document.all[layerID].style.visibility=&quot;hidden&quot;;
}
// -->
</SCRIPT>

<STYLE type=text/css>
#layerA {
BACKGROUND-COLOR: #FFFFFF; LEFT: 10px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden; WIDTH: 300px
}
#layerB {
BACKGROUND-COLOR: #FFFFFF; LEFT: 10px; POSITION: absolute; TOP: 80px; VISIBILITY: hidden; WIDTH: 300px
}
</STYLE>
</head>
<body>

<A href=&quot;#&quot; onmouseout=hideIt('layerA'); onmouseover=showIt('layerA');>Link A</a>
<A href=&quot;#&quot; onmouseout=hideIt('layerB'); onmouseover=showIt('layerB');>Link B</a>
<div id=&quot;layerA&quot;>AAAAAAAA</div>
<div id=&quot;layerB&quot;>BBBBBBBB</div>
</body>
</html>

Hope this is what you are looking for? :p

Gtz,

Kristof

PS: notice the difference i made for NS show/hide and IE visible/hidden. Doesn't seem to matter much but you can never be sure enough :)
 
kristof, last week i was told that netscape supports &quot;hidden&quot;.. weird.. i really didnt kno that before, & it works in nn4.61 (wich i have) & i think in others..

u never know what is goin on around here.. Victor
 
It does? Hm, will that browser ever make sense? X-)

Oh well, was a small remark anyhow, so mikeyK, you can ignore my PS.

Still, it might be wise to include it because of the older NS versions? Or should it be disregarded totally?

Gtz (and tnx for the info vituz),

Kristof
 
no, i think we shuld leave it like it is told in netscrap documentation: hide
at least i wont change anything in my codes :)

but it was interesting to know.. Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top