меню вложенности ul>li.nav-item>a второй уровень внутри li , Опять ul->li>a Но без классса.
Добавляется active
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$(document).ready(function(e) { var pathname_url = window.location.pathname; var href_url = window.location.href; //console.log('pathname_url ',pathname_url); //console.log('href_url ',href_url); $(".navbar-nav li").each(function () { var link = $(this).find("a").attr("href"); // console.log('link ',link); if(pathname_url == link || href_url == link) { let a=$(this).children("a"); a.addClass("active"); // console.log($(this).closest('li.nav-item').html()); if($(this).closest('li.nav-item').length) { $(this).closest('li.nav-item').children("a").addClass('active'); } } }); |