Skip to content

Instantly share code, notes, and snippets.

@itsmattsoria
Created May 16, 2014 20:12
Show Gist options
  • Save itsmattsoria/60e3d006dfb86e0b6fd3 to your computer and use it in GitHub Desktop.
Save itsmattsoria/60e3d006dfb86e0b6fd3 to your computer and use it in GitHub Desktop.
giving current page item in menu, or current parent page item in menu an active class
http://blog.huidesign.com/automatically-highlight-current-page-in-navigation-with-css-jquery/
var str=location.href.toLowerCase();
$(".nav a").each(function() {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$("li.current").removeClass("current");
$(this).parent().addClass("current");
}
});
$("li.current").parents().each(function(){
if ($(this).is("li")){
$(this).addClass("current");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment