Skip to content

Instantly share code, notes, and snippets.

@yuriitaran
Forked from agragregra/jquery-active.js
Last active February 4, 2018 11:04
Show Gist options
  • Save yuriitaran/27b4fcd0a49621ea632fed2cb776b711 to your computer and use it in GitHub Desktop.
Save yuriitaran/27b4fcd0a49621ea632fed2cb776b711 to your computer and use it in GitHub Desktop.
jQuery Active Menu
// Active menu
$("li a").each(function() {
if (this.href == window.location.href) {
$(this).addClass("active");
}
});
// second way
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,"") + "$");
$(".box-mnu a").each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,""))){
$(this).addClass("active");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment