PDA

View Full Version : Switch Menu - Closing Sub Categories



don817
03-01-2006, 05:48 PM
On this menu, some of the buttons (contact us and newswire) don't have subcategories. When you click on them, it leaves the previous menu open. Is there a way to have it close then back when going to those two categories without a submenu.

http://www.woundcarestrategies.com/newsite/welcome.html

Thanks!!

bredding
03-05-2006, 07:05 PM
I just did this for one of my sites ----

I included

onclick="SwitchMenu('sub#')"

(where # is the next number in the sequence) for those links that do not have submenus. Then I Included

<span class="submenu" id="sub#">
<span>

jscheuer1
03-06-2006, 05:54 AM
That's a very nice solution, bredding. I came up with this one a while back, a bit more complex but, it allows for simpler markup:

Find the function SwitchMenu and replace it with this one:


function SwitchMenu(obj){
if(document.getElementById){
if (typeof obj!=='undefined')
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
if(typeof obj=='undefined'||el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
}
if (typeof obj=='undefined')
return;
el.style.display = "block";
}else{
el.style.display = "none";
}
}
}

Use this syntax for the 'dummy' menu item:


<div class="menutitle" onclick="SwitchMenu()">Cool Links</div>

don817
03-06-2006, 09:45 PM
Thanks for the help!!