Skip to content

Instantly share code, notes, and snippets.

@zachharkey
Created December 13, 2013 21:19
Show Gist options
  • Save zachharkey/7951514 to your computer and use it in GitHub Desktop.
Save zachharkey/7951514 to your computer and use it in GitHub Desktop.
var url = window.location.href;
// Will only work if string in href matches with location
$('.menu a[href="'+ url +'"]').addClass('active');
// Will also work for relative and absolute hrefs
$('.menu a').filter(function() {
return this.href == url;
}).addClass('better-active');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment