I have found the following jquery code for an drop-down-menu.
What should the HTML code contain to work with it?
jQuery(document).ready(function(){
jQuery("html").bind("click", function (e) {
jQuery('.dropdown-toggle, a.menu').parent("li").removeClass("open");
});
jQuery(".dropdown-toggle, a.menu").click(function(e) {
// First look an see if a menu is open. If it is, then just close it.
if (jQuery(this).parent("li").hasClass("open")) {
jQuery("ul").find('li').removeClass('open');
}
// If menu was not open, then close any other menus that were open and just open the one.
else {
jQuery("ul").find('li').removeClass('open');
jQuery(this).parent("li").addClass('open');
}
return false;
});
});
You need this HTML:
Or, another method:
Inside the
<UL>, you need to give this way:If you want to give a divider, you can give this way:
If you wanna invoke it by JavaScript, you can use this code:
And it displays this way:
It is Twitter Bootstrap‘s JavaScript DropDown menu plugin. You can know more about it here.