Skinny
Feb 2nd 2008, 12:25 pm
Hey guys Okay I'm looking to hide a set of divs.
Let's say I have an unknown amount of divs that all share the same id (so that they can be hid and shown at the same time).
So I want a checkbox that will toggle them all on or off (checkbox will be checked initially).
How do I build this.
So far I have this code here as an example but it's not working (and the checkbox isn't checked at the start.
<head>
<script type="javascript">
function toggle(ID) {
var el = document.getElementById(ID);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
</script>
</head>
<body>
<form>
<input type="checkbox" onClick="toggle(descr);"> See Descriptions
</form>
<div id="descr">Hello This is #1</div>
<div id="descr">Hello This is #2</div>
<div id="descr">Hello This is #3</div>
</body>
Let's say I have an unknown amount of divs that all share the same id (so that they can be hid and shown at the same time).
So I want a checkbox that will toggle them all on or off (checkbox will be checked initially).
How do I build this.
So far I have this code here as an example but it's not working (and the checkbox isn't checked at the start.
<head>
<script type="javascript">
function toggle(ID) {
var el = document.getElementById(ID);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
</script>
</head>
<body>
<form>
<input type="checkbox" onClick="toggle(descr);"> See Descriptions
</form>
<div id="descr">Hello This is #1</div>
<div id="descr">Hello This is #2</div>
<div id="descr">Hello This is #3</div>
</body>