Javascript to show/hide many divs

Javascript code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script language="javascript">
<!--
 
var state = 'none';
 
function showhide(layer_ref) {
 
if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}
//--<
</script>;

HTML code

1
2
<p><a href="#" onclick="showhide('div1');">show/hide me</a></p>
<div id="div1" style="display: none;">This is the content</div>

Leave a Reply

Your email address will not be published. Required fields are marked *