Skip to content

Instantly share code, notes, and snippets.

@haojianzong
Created December 28, 2014 03:36
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 haojianzong/c7ab2b71a4f955b1bbdb to your computer and use it in GitHub Desktop.
Save haojianzong/c7ab2b71a4f955b1bbdb to your computer and use it in GitHub Desktop.
jQuery Auto Active Menu
// this function will active menu using href match
// Author: http://www.paulund.co.uk/use-jquery-to-highlight-active-menu-item
function auto_active_menu() {¬
var url = window.location.href;¬
// Work for relative and absolute hrefs¬
$('.menu a').filter(function() {
return this.href == url;¬
}).addClass('active');¬
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment