I just started coding in jQuery last week and need some help figuring out how to make a menu work properly. I have 3 tabs each with their own menu. When a page is displayed a menu and a sub menu is automatically displayed. Once it's displayed the user can hover over the tabs to see the other sub menus and when they stop hovering the originally sub menu appears.
My issue is that although, I can show them the sub menu of the other tabs, I can't keep the sub menu open for the user to click on a sub menu item. Other tutorials show how to do this only when the sub menu is nested within a parent element, but my code for the menu structure doesn't have the sub menus nested (this is how the code was when I joined the project). Is there some way I can keep the sub-menu open if the user hovers on the respective tab?
Here is my menu HTML:
<div id="navigation">
<div id="main-nav">
<div id="kids"><a href="../images/nav1.png"></a></div>
<div id="community"><a href="../images/nav2.png"></a></div>
<div id="about"><a href="../images/nav3.png"></a></div>
</div>
</div>
<div id="sub-nav">
<ul class="menu-1 requiresJS">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
<li><a href="#">Item3</a></li>
<li><a href="#">Item4</a></li>
<li><a href="#">Item5</a></li>
<li><a href="#">Item6</a></li>
</ul>
<ul class="menu-2 requiresJS">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
<li><a href="#">Item3</a></li>
<li><a href="#">Item4</a></li>
<li><a href="#">Item5</a></li>
<li><a href="#">Item6</a></li>
</ul>
<ul class="menu-3 requiresJS">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
<li><a href="#">Item3</a></li>
<li><a href="#">Item4</a></li>
<li><a href="#">Item5</a></li>
<li><a href="#">Item6</a></li>
</ul>
Here is my jQuery thus far:
// For JS users, display sub menus by default
$(".requiresJS").css("display","block");
var startMenu
//hide all sub menus
$("#sub-nav ul").hide();
// check URL for about, community or kids and set startMenu with correct term
if(window.location.href.indexOf("about") != -1){startMenu = "about"}
else if(window.location.href.indexOf("community") != -1){startMenu = "community"}
else{startMenu = "kids"}
// highlight correct category tab
$("div#main-nav #" + startMenu).addClass("selected");
// show correct starting menu
$("#sub-nav ul.menu-" + startMenu).show('slide', {direction: 'right'}, 600).effect("bounce", { times:1,direction:"right",distance:13 }, 300);
// show correct menu on mouseover of div
$("div#main-nav div").mouseover(function() {
$("#sub-nav ul").stop(true, true)
$("#sub-nav ul").hide();
var currentId = $(this).attr('id');
$("#sub-nav ul.menu-" + currentId).show();
});
$("div#main-nav div").mouseover(function() {
$("#sub-nav ul").stop(true, true)
$("#sub-nav ul").hide();
var currentId = $(this).attr('id');
$("#sub-nav ul.menu-" + currentId).show();
});