Answer the question
In order to leave comments, you need to log in
Highlight active menu item and expand sidebar-item (Bootstrap 4)?
Tell me how to highlight the active menu item on the sidebar
<nav id="sidebar" class="sidebar">
<ul class="sidebar-nav">
<li class="sidebar-item"><a href="/../<?=$rowCat['url']?>/" class="sidebar-link"><i class="<?=$rowCat['image_category']?>"></i> <span class="align-middle"><?=$rowCat['name_category']?></span></a></li> // Первый уровень
<ul id="cat<?=$rowCat['id']?>" class="sidebar-dropdown list-unstyled collapse" data-parent="#sidebar">
<li class="sidebar-item"><a class="sidebar-link" href="/../<?=$rowSubCat['url']?>/"><?=$rowSubCat['name_category']?></a>
</li> // Второй уровень
</ul>
</ul>
</nav>
<li class="sidebar-item">
<ul id="cat<?=$rowCat['id']?>" class="sidebar-dropdown list-unstyled collapse" data-parent="#sidebar">
$(function () {
var links = $('.sidebar sidebar-item');
var url = (new URL(document.URL)||{});
$.each(links, function (key, va) {
var Link = (new URL(va.href)||{});
Link.search = url.search;
if (Link.href == url.href ) {
$(this).addClass('active').parent().addClass('show');
}
});
});
Answer the question
In order to leave comments, you need to log in
1. php: specify the relative path (path) completely and without links like "/../"
2. js: window.location.pathname current relative path, you must first remove the active/show class the previous active element
in bootstrap4 does not have a sidebar element -item is similar to nav-item?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question