Skip to content

Instantly share code, notes, and snippets.

@revaboogy
Created February 20, 2014 16:54
Show Gist options
  • Save revaboogy/9118310 to your computer and use it in GitHub Desktop.
Save revaboogy/9118310 to your computer and use it in GitHub Desktop.
Adding Class to current menu item or link
$(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;
$('#main-menu a[href="'+url+'"]').addClass('current_page_item');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment