<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
<script type="text/javascript">
<!--
if (document.getElementById) onload = function () {
var list = document.getElementById ('list').getElementsByTagName ('li');
for (var i = 0; i < list.length; i++) list[i].className = 'hidden';
var body = document.getElementsByTagName ('body')[0];
var ul = document.createElement ('ul');
body.appendChild (ul);
var li, input, s;
i = 0;
while (s = ['foo', 'bar'][i++]) {
li = document.createElement ('li');
ul.appendChild (li);
input = document.createElement ('input');
input.setAttribute ('type', 'checkbox');
li.appendChild (input);
li.appendChild (document.createTextNode(s));
input.onclick = function () {
var list = document.getElementById ('list').getElementsByTagName ('li');
var these = this.parentNode.parentNode.getElementsByTagName ('input');
if (these[0].checked && these[1].checked) {
list[0].className = list[1].className = 'hidden';
list[2].className = '';
} else {
list[2].className = 'hidden';
for (var i = 0; i < list.length; i++) list[i].className = these[i].checked ? '' : 'hidden';
}
}
}
}
// -->
</script>
<style type="text/css">
.hidden {display:none}
</style>
</head>
<body>
<ul id="list">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</body>
</html>
JavaScript being iffy you want to hide things with JavaScript from the get go and you want to use JavaScript to create any element that only has meaning when JavaScript works.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
The easiest way is to first hide all the DIV's and show only the desired. For this you need to group the elements somehow, to be able to circle through them. A basic example:
Bookmarks