Skip to content

Instantly share code, notes, and snippets.

@BryanBarrera
Created April 11, 2020 18:34
Show Gist options
  • Save BryanBarrera/a62915d25bc487c15c4373889fa83ccf to your computer and use it in GitHub Desktop.
Save BryanBarrera/a62915d25bc487c15c4373889fa83ccf to your computer and use it in GitHub Desktop.
If URL matches HREF, add Class
if ( ('.element').length ) {
var url = window.location.pathname;
$('.element a').each(function() {
var href = $(this).attr('href');
if (url.indexOf(href) > -1) {
jQuery(this).parent().addClass('is-active');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment