# Little java script for a menu

**URL:** <https://forum.kirupa.com/t/little-java-script-for-a-menu/243838>\
**Category:** programming\
**Created:** [November 11, 2007, 6:27pm UTC](https://forum.kirupa.com/t/little-java-script-for-a-menu/243838 "2007-11-11T18:27:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dali](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@Dali](https://forum.kirupa.com/u/Dali)\
**Post date:** [November 11, 2007, 6:27pm UTC](https://forum.kirupa.com/t/little-java-script-for-a-menu/243838/1 "2007-11-11T18:27:58Z")

</div>

Have trouble finding a missing piece of the script for a simple menu. The menu is : menu tree - click to open, click to close category. Categories and sub cat are in unordered list, placed in a \<div\>. Have the following script for the click-function:… The prob is, once i’ve clicked on the subcategory, the menu folds. Want it simply to keep open until another main category is pressed. I’m really not into java, so every little help is appreciated.  
The js i’ve found for now:  
clickMenu = function(menu) {  
var getEls = document.getElementById(menu).getElementsByTagName(“LI”);  
var getAgn = getEls;

```
for (var i=0; i&lt;getEls.length; i++) {
        getEls*.onclick=function() {
            for (var x=0; x&lt;getAgn.length; x++) {
            getAgn[x].className=getAgn[x].className.replace("unclick", "");
            getAgn[x].className=getAgn[x].className.replace("click", "unclick");
            }
        if ((this.className.indexOf('unclick'))!=-1) {
            this.className=this.className.replace("unclick", "");;
            }
            else {
            this.className+=" click";
            }
        }
        getEls*.onmouseover=function() {
            this.className+=" hover";
        }
        getEls*.onmouseout=function() {
            this.className=this.className.replace("hover", "");
        }
    }
}
```
