I want to design a multilevel menu using jQuery. I have already written some code .You can see the demo here . All this works fine. But I want to make multilevel drop down menus dynamically.
Script
$('ul#menu > li').hover(function(){
//$('#drop' , this).css('display','block');
$('.drop' , this).delay(20).slideDown(200);
}, function(){
$('.drop' , this).delay(20).slideUp(200);
});
HTML
<ul id="menu">
<li><a href="#">Home</a>
<ul class="drop">
<li><a href="#">About us</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">About us</a></li>
</ul>
</li>
<li><a href="#">about</a>
<ul class="drop">
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul>
</li>
</ul>
CSS
ul#menu
{
margin:0;
padding:0;
}
ul#menu > li
{
list-style:none;
float:left;
margin:0;
padding:0;
position:relative;
}
ul#menu a
{
text-decoration:none;
color:#fff;
background:red;
display:block;
padding:10px;
}
ul#menu > li ul.drop
{
margin:0;
padding:0;
width:150px;
position:absolute;
display:none;
}
ul#menu > li ul.drop ul
{
margin:0;
padding:0;
width:150px;
position:absolute;
display:none;
left:150px;
top:0;
}
ul#menu > li ul li
{
margin:0;
padding:0;
list-style:none;
position:relative;
}
You need to change the jQuery script a little to accommodate for the multilevel menus like this:
and change html like this:
Your css is fine. You can check the updated multilevel code at: http://jsfiddle.net/297t6/
for live demo see this link: http://jsfiddle.net/nanoquantumtech/Z5NXv/