Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Show/Hide JS

// Will show/hide on click

<html>
<head>
<script>
function layerSetup(id,visibility){
if(document.getElementById){
this.obj = document.getElementById(id).style;
this.obj.visibility = visibility;
return this.obj;}
else if(document.all){
this.obj = document.all[id].style;
this.obj.visibility = visibility;
return this.obj;}
else if(document.layers){
this.obj = document.layers[id];
this.obj.visibility = visibility;
return this.obj;}
}
function visVisible(param){
new layerSetup(param,'visible');
}

function visHidden(param){
new layerSetup(param,'hidden');
}
</script>
</head>

<body>
<a href="#" onclick="visVisible('id1')">SHOW1</a> 
<a href="#" onclick="visVisible('id2')">SHOW2</a>
<a href="#" onclick="visVisible('id3')">SHOW3</a><br>
<br>
<a href="#" onclick="visHidden('id1')">HIDE1</a> 
<a href="#" onclick="visHidden('id2')">HIDE2</a>
<a href="#" onclick="visHidden('id3')">HIDE3</a> 
<br>
<br>
<div id="id1">ID1</div><br>
<div id="id2">ID2</div><br>
<div id="id3">ID3</div>
</body>
</html>

You need to create an account or log in to post comments to this site.