Skip to content

Instantly share code, notes, and snippets.

@Linell
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linell/9db398b8c68241869df5 to your computer and use it in GitHub Desktop.
Save Linell/9db398b8c68241869df5 to your computer and use it in GitHub Desktop.
Loops through each a tag in the `#navbar` and compares it to the url. If it's a match BOOM add active to it.
$(document).ready(function() {
p = location.pathname.replace('/', '').split('/')[0];
$("#navbar a").each(function() {
if ( $(this).attr('href').replace('/', '') == p ) {
$(this).parent().addClass('active');
return;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment