Sometimes we need to add active class to our custom menu items or sidebar menus. Simple bit of jQuery to add an active class to the current navigation item based on the page url.

JavaScript

Add the following code in javascript :

jQuery("nav a").each(function() {   
    if (this.href == window.location.href) {
        jQuery(this).addClass("active-sidebar");
    }
});

Now your menu items will have active class in the menu items.

Don’t forget to share this blog and bookmark this site. We publish error solutions so that it will help to speed up the development.

enjoy the coding. 🙂

There are currently no comments.