jQuery, Tutorials, Wordpress

jQuery active class based on the page url

23 August 2018

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.


Add the following code in javascript :

jQuery("nav a").each(function() {   
    if (this.href == window.location.href) {

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. 🙂

Leave a Comments