Skip to content

Instantly share code, notes, and snippets.

@AntonLitvin
Last active July 3, 2017 13:36
Show Gist options
  • Save AntonLitvin/19176a0da3c6400dee63beb55edf4c6d to your computer and use it in GitHub Desktop.
Save AntonLitvin/19176a0da3c6400dee63beb55edf4c6d to your computer and use it in GitHub Desktop.
//Active menu, absolute url
$('.menu a').each(function() {
if (this.href == window.location.href) {
$(this).addClass('active');
}
});
//Active menu, relative url
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + '$');
$('.menu 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