Skip to content

Instantly share code, notes, and snippets.

@sanusart
Created April 15, 2015 16:31
Show Gist options
  • Select an option

  • Save sanusart/2872fa4d22804615b055 to your computer and use it in GitHub Desktop.

Select an option

Save sanusart/2872fa4d22804615b055 to your computer and use it in GitHub Desktop.
Active link on ul > li > a #jquery #javascript
// 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