jcadima
10/28/2016 - 8:14 PM

Add active class to menu

Add active class to menu



https://css-tricks.com/snippets/jquery/add-active-navigation-class-based-on-url/



jQuery(document).ready(function(){

 var newURL = window.location.protocol + "//" + window.location.host  + window.location.pathname;
 // https://perfume-surprise.cratejoy.com/
 console.log("FULL URL: " + newURL);
  if( newURL == "https://perfume-surprise.cratejoy.com/" ) {
    console.log("HOMEPAGE") ;
    // empty , we dont want to add active class to the homepage
   
  }  
  else {
    console.log("NOT HOMEPAGE") ;
    // add active class to the navbar when its not the homepage
     $('#navbar-menu a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active'); 
  }


})  ;