billyboy
11-27-2006, 12:05 PM
This bit of javascript almost does what I want. It toggles the display of submenus when a list item is clicked. What I would also like is to hide the submenu that is showing when another selection is made. I just can't figure out how, and would appreciate some help.
function toggle() {
var el=document.getElementById("menu").getElementsByTagName("li");
for (i=0; i<el.length; i++) {
el[i].className = "hide";
el[i].onclick = function() {
this.className = (this.className == "hide") ? "show" : "hide";
}
}
}
Then in the CSS I have defined the properties for the classes to hide the submenus until selected, and the markup is just a series of nested uls with the top level ul given the id "menu".
Also I was wondering if its possible to make it work on mouseover/mouseout as well as onclick.
function toggle() {
var el=document.getElementById("menu").getElementsByTagName("li");
for (i=0; i<el.length; i++) {
el[i].className = "hide";
el[i].onclick = function() {
this.className = (this.className == "hide") ? "show" : "hide";
}
}
}
Then in the CSS I have defined the properties for the classes to hide the submenus until selected, and the markup is just a series of nested uls with the top level ul given the id "menu".
Also I was wondering if its possible to make it work on mouseover/mouseout as well as onclick.