Site icon Shaharia's Blog

Keep navigation link active with jQuery

After clicking on any navigation link in navgation and whenever that page will be open then one active class will be added in that element.

$(document).ready(function(){
 var a = $('.navbar-nav a');
 a.each(function(){
   if(window.location.href == $(this).attr('href')){
     $(this).closest('li').addClass('active');
   }
 })
})