Skip to content

Instantly share code, notes, and snippets.

@levifig
Created October 5, 2010 04:10
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 levifig/610978 to your computer and use it in GitHub Desktop.
Save levifig/610978 to your computer and use it in GitHub Desktop.
Goes through the links in my <nav> and compares their own 'href' with the current URL.
// Goes through the links in my navigation and compares their own 'href' with the current URL
// Really handy and I'm sure I'll reuse hence posting it here. ;)
// Thank you to Paul Irish (#jquery @ freenode.net) for the indexOf recommendation! ;)
$('nav ul li a').each(function() {
if (location.pathname.indexOf($(this).attr('href')) > -1 ) {
$(this).addClass('active');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment