Created
April 15, 2015 16:31
-
-
Save sanusart/2872fa4d22804615b055 to your computer and use it in GitHub Desktop.
Active link on ul > li > a #jquery #javascript
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
| // Match href element with path and add class "active-link" | |
| var this_url = document.location.pathname, | |
| list_sidebar_link = $('.some-selector ul li a'); | |
| $(list_sidebar_link).each(function (i, item) { | |
| var the_a = list_sidebar_link[i]; | |
| if (this_url === $(the_a).attr('href')) { | |
| $(the_a).addClass('active-link'); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment