Active menu item with multi level submenus
See original GitHub issueHi, I’m using this code to add active class depending of the page.
This is working ok except for multi level submenus any clue how to fix this
/** add active class and stay opened when selected */
var url = window.location;
// for sidebar menu entirely but not cover treeview
$('ul.sidebar-menu a').filter(function() {
return this.href == url;
}).parent().addClass('active');
// for treeview
$('ul.treeview-menu a').filter(function() {
return this.href == url;
}).closest('.treeview').addClass('active');
<li class="treeview">
<a href="#">
<i class="fa fa-gears"></i>
<span>Settings</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="#">
<i class="fa fa-bars"></i>
Specials Settings
</a>
<ul class="treeview-menu">
<li><a href="setting1.php">Setting 1</a></li>
</ul>
</li>
</ul>
</li>
Issue Analytics
- State:
- Created 6 years ago
- Comments:34
Top Results From Across the Web
How to make only the valid active page of a multilevel ...
This is purely a CSS question, and has nothing to do with WordPress, but the answer is simple enough. You need to use...
Read more >Multilevel Menu Design Best Practices
Apply these guidelines to design intuitive multilevel menus that increase ... If the current page is in a submenu, highlight the submenu link...
Read more >Bootstrap nested (multilevel) Dropdown - free examples
Nested dropdowns built with Bootstrap 5. Tutorial & templates for multilevel navbar dropdowns menu, activated on hover or on click & much more....
Read more >How to create a multilevel dropdown menu in React
Multilevel menus are designed to reveal the deeply nested navigations when we click or hover over the submenu items, as shown in the...
Read more >Bootstrap 5 navbar with multilevel dropdown menu
This is fully responsive multilevel dropdown navbar code sample. It is also called treeview menu. 1-st level dropdowns are opens by click, but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ul.level-1
from? 😄 AdminLTE doesn’t use something like this.i fixed it to get it work on AdminLTE
i tested all variations till level 3 (all items) 😃
I have fixed it now it will show only matching url as active rest as inactive
add active class and stay opened when selected