Last active
December 21, 2015 06:59
-
-
Save micronax/6267917 to your computer and use it in GitHub Desktop.
Small jQuery hack to add "active" class to <li> of current navigation link based on href-attribute and window.location
This file contains 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
// if you use absolute urls | |
$('a[href="'+window.location+'"]').parent().addClass('active'); | |
// if you use relative urls | |
$('a[href="'+window.location.pathname+'"]').parent().addClass('active'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment