Created
March 3, 2013 14:12
-
-
Save galaakk/5076263 to your computer and use it in GitHub Desktop.
JS: Add active class for current URL (works with all URIs)
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
| var url = window.location; | |
| $('nav a').filter(function() { | |
| return this.href == url; | |
| }).addClass('active'); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Best way I've found to achieve this effect. All URL formats are ok with this one, it seems.
Just have a nav tag with an ul and some li>a in it, style the .active class in CSS, and let's go !
You need first to call jQuery or Zepto, of course.