kippie
08-09-2004, 11:42 AM
In the HTM below there is a function to show and hide layers. With the command "hideLayers();" all layers are hidden. I wonder if it is possible to change the function so that with "hideLayers();" one type of layers (dependent on the name) answer to this function and disappear (layer1 and layer2), while the others don't and stay (otherlayer).
This is the HTML with the function:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 4">
<title>Welcome to Adobe GoLive 4</title>
<script language="javascript">
function hideLayers(sel) {
var eles = document.getElementsByTagName("div");
var all = (sel) ? 0 : 1;
if(all){
for(i=0;i<eles.length;i++) {
document.getElementById(eles[i].id).style.visibility="hidden";
}
}
else{
for(i=0;i<eles.length;i++) {
if(eles[i].id==sel) document.getElementById(eles[i].id).style.visibility="hidden";
}
}
}
function showLayer(sel) {
var eles = document.getElementsByTagName("div");
for(i=0;i<eles.length;i++) {
if (eles[i].id==sel) {
document.getElementById(sel).style.visibility="visible";
}
}
}
</script>
<style type="text/css"><!--
#layer1{ position: absolute; top: 16px; left: 16px; width: 100px; height: 100px; visibility: visible }
#layer2 { position: absolute; top: 148px; left: 217px; width: 100px; height: 100px; visibility: hidden }
#otherlayer { position: absolute; top: 10px; left: 249px; width: 100px; height: 100px; visibility: visible }
-->
</style>
</head>
<body>
<div id="layer1">
This is layer 1</div>
<div id="layer2">
This is layer 2</div>
<div id="otherlayer">
This is OtherLayer</div>
<br><br><br><br><br>
<a href="#" onClick="hideLayers();">Hide all layers</a><br>
<a href="#" onClick="hideLayers('layer1');">Hide layer1</a><br>
<a href="#" onClick="hideLayers('layer2');">Hide layer2</a><br>
<a href="#" onClick="showLayer('layer2');">Show layer2</a><br>
</body>
</html>
This is the HTML with the function:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 4">
<title>Welcome to Adobe GoLive 4</title>
<script language="javascript">
function hideLayers(sel) {
var eles = document.getElementsByTagName("div");
var all = (sel) ? 0 : 1;
if(all){
for(i=0;i<eles.length;i++) {
document.getElementById(eles[i].id).style.visibility="hidden";
}
}
else{
for(i=0;i<eles.length;i++) {
if(eles[i].id==sel) document.getElementById(eles[i].id).style.visibility="hidden";
}
}
}
function showLayer(sel) {
var eles = document.getElementsByTagName("div");
for(i=0;i<eles.length;i++) {
if (eles[i].id==sel) {
document.getElementById(sel).style.visibility="visible";
}
}
}
</script>
<style type="text/css"><!--
#layer1{ position: absolute; top: 16px; left: 16px; width: 100px; height: 100px; visibility: visible }
#layer2 { position: absolute; top: 148px; left: 217px; width: 100px; height: 100px; visibility: hidden }
#otherlayer { position: absolute; top: 10px; left: 249px; width: 100px; height: 100px; visibility: visible }
-->
</style>
</head>
<body>
<div id="layer1">
This is layer 1</div>
<div id="layer2">
This is layer 2</div>
<div id="otherlayer">
This is OtherLayer</div>
<br><br><br><br><br>
<a href="#" onClick="hideLayers();">Hide all layers</a><br>
<a href="#" onClick="hideLayers('layer1');">Hide layer1</a><br>
<a href="#" onClick="hideLayers('layer2');">Hide layer2</a><br>
<a href="#" onClick="showLayer('layer2');">Show layer2</a><br>
</body>
</html>