I just developed a single level dropdown menu using jquery… How to refactor the same code to make it a multilevel dropdown menu…
Here is my working sample….
The jquery what i used,
$(document).ready(function() {
$("#Programming ul.child").removeClass("child");
$("#Programming li").has("ul").hover(function() {
$(this).addClass("current").children("ul").fadeIn();
}, function() {
$(this).removeClass("current").children("ul").stop(true, true).css("display",
"none");
});
});
EDIT:
Menu1 Menu2
SubMenu1 SubMenu1
Submenu2 SubMenu2
SubMenu21
SubMenu22
The second submenu level can be anywere…
Here is my solution:
http://jsbin.com/oteze/9
I tested it on Firefox 3.6.8.
ADD: Now it works in IE7 too.
You can nest any number of submenus anywhere. Just like that:
I modified your code a little, so there is difference between first level submenu and other levels. I also moved all show/hide logic to JS.