Dynadot

JavaScript Expand/Collapse

Namecheap
Impact
2
Hi all!

If your in need of a simple script to have an expandable/collapsable menu, use my script:
HTML:
<script langauge="JavaScript" type="text/javascript">
function doMenu(item) {
 obj=document.getElementById(item);
 col=document.getElementById("x" + item);
 if (obj.style.display=="none") {
  obj.style.display="block";
  col.innerHTML="[-]";
 }
 else {
  obj.style.display="none";
  col.innerHTML="[+]";
 }
}
</script>
Then just layout a simple div:
HTML:
<a href="JavaScript:doMenu('main');" id=xmain>[+]</a> Main Item
<div id=main style="margin-left:1em">
 <a href=#>Item 1</a><br>
 <a href=#>Item 2</a><br>
 <a href=#>Item 3</a>
</div>
<br>

This should work in Internet Explorer 4.x+ and Firefox but you'll have to do a few checks to make it Netscape compatiable (which im not gonna explain).
 
Top