Filter and Hooks

add active class to the current menu using jquery

Sometimes, it is handy to use jQuery to highlight the current menu. And for such cases you can write script that automatically add active class to the current menu:

jQuery('a[href*="'+window.location.href+'"]').addClass('current-menu');

If the menu to be highlighted is inside the container with class for eg. ‘main-nav’, then it would be good to add ‘.main-nav’ on the selector.

jQuery('.main-nav a[href*="'+window.location.href+'"]').addClass('current-menu');

Views: 23

Standard