Skip to content

Instantly share code, notes, and snippets.

@geilt
Created September 12, 2014 17:25
Show Gist options
  • Save geilt/c402b8e6bb809185a269 to your computer and use it in GitHub Desktop.
Save geilt/c402b8e6bb809185a269 to your computer and use it in GitHub Desktop.
Highlight a menu item based on URL. Modify to your needs
/**
* Highlight Current Menu Item
*/
var currentLocation = window.location.pathname;
$('#top-menu a').each( function(){
if( $(this).attr('href') == currentLocation ){
$(this).closest('li').addClass('active');
$(this).closest('.main_menu').addClass('active');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment