Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I've two navigation menu - left dashboard and top main nav. There are some common links and same behavior. I wanna trigger click event for both navigation and response for same page with adding the active class on current sub menu.

Here is my code :

var url = window.location.href;
// Will also work for relative and absolute hrefs
$('.main-nav li a').filter(function () { //, .subnav-menu li a
return url.toLowerCase().indexOf((this.href).toLowerCase()) >= 0;
}).parent().addClass('active');

$('.main-nav li ul li a').filter(function () {//, .subnav-menu li ul li a
return url.toLowerCase().indexOf((this.href).toLowerCase()) >= 0;
}).parent().parent().parent().addClass('active');

$(".main-nav li a, .subnav-menu li a").on('click', function() {
$('.main-nav li, .subnav-menu li').removeClass('active');
$(this).parent('li').addClass('active');

});
$(".main-nav li ul li a, .subnav-menu li ul li a").on('click', function() {
$('.main-nav li, .subnav-menu li').removeClass('active');
$(this).parent().parent().parent('li').addClass('active');

});


The problem with adding active class on nav li.
Thanking You.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900