I just got a fix on another post I just made but this created a nother problem. I am working on a navigation menu with multiple levels. Here is the script I am using:
$(document).ready(function(){
// attach the click handler for the menu
$(".left-navigation-holder li a[href='']:has(~ul)").click(toggleMenu);
// Expand menu for the current page:
var level1Selector = "#" + $("body").attr("menul1");
var level2Selector = "#" + $("body").attr("menul2");
var level3Selector = "#" + $("body").attr("menul3");
$(".left-navigation-holder li a:has(~ul"+ level1Selector +")").click();
$(".left-navigation-holder li a:has(~ul"+ level2Selector +")").click();
$(".left-navigation-holder li a:has(~ul"+ level3Selector +")").click();
});
// menu toggle function
function toggleMenu() {
//if ($(this).attr(href='#')) {alert("yes")} else {alert("no")}
$(this).siblings("ul").toggle();
$(this).closest("li").toggleClass("selected");
return false;
}
The first line initiate the menu by saying that if there is a click event on one link in the menu and if that link has an empty href attribute and a list further down, then it fires toggleMenu to open that level. The reason for checking for the value of href is that if is empty, the menu opens, if not it sends the user to the URL value and does not toggle the menu. That leaves the option to have a page link for some menus (and keep sub-levels) when other are just here to toggle the sub menu.
The other part of the script reads the values of the attributes I have set in the body tag on each page (menul1, menul2, menul3) to know on what page in the menu we are so the menu opens the right menu levels when the page loads.
The problem I have is that because the first line checks for the value of the href attribute, if the page loaded was called by clicking a menu that had a link and a sub menu, that one does not open when loading the page because the href has a value. The 3 lines that were initiating each levels now only work when the href value is empty.
Not sure what to do. Help would be appreciated. I hope this was clear enough.
Thanks!