Created
May 16, 2014 20:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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