Add Active Navigation Class Based on URL
The reason this isn’t working is because the javascript is executing, then the page is reloading which nullifies the ‘active’ class. What you probably want to do is something like: $(function(){ var current = location.pathname; $(‘#nav li a’).each(function(){ var $this = $(this); // if the current path is like this link, make it active if($this.attr(‘href’).indexOf(current) … Read more