I have a dropdown menu nested in a navbar that I am opening during page load by adding the open
class to the li
element containing the dropdown men
This uses only css. working demo
Add a class to the dropdown ul (.stay-open)
<ul class="dropdown-menu stay-open">
then apply style display block with !important
.stay-open {display:block !important;}
I am assuming that you are using a bootstrap dropdown, give this a shot:
$('li.dropdown').on({
"shown.bs.dropdown": function() { this.close = false; },
"click": function() { this.close = true; },
"hide.bs.dropdown": function() { return this.close; }
});
The above implementation will hide the dropdown when it is clicked again. If you do not like that behavior, you can simply remove the first two lines (shown.bs.dropdown and click events) and simply return false for hide.bs.dropdown event.
Here is working proof bootply
Here is a working proof bootply that will always stay open