Skip to content

Instantly share code, notes, and snippets.

@andyknapp
Created October 10, 2013 16:35
Show Gist options
  • Save andyknapp/6921420 to your computer and use it in GitHub Desktop.
Save andyknapp/6921420 to your computer and use it in GitHub Desktop.
add a class to menu item based on matching (absolute) urls.
jQuery(document).ready(function($){
// Get current url
// Select an a element that has the matching href and apply a class of 'active'. Also prepend a - to the content of the link
var url = window.location.href;
$('.menu a[href="'+url+'"]').addClass('current_menu_item');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment