Skip to content

Instantly share code, notes, and snippets.

@uwang
Last active March 27, 2017 04:59
Show Gist options
  • Save uwang/b9db3972a6a4c037abe9fc564f610ef4 to your computer and use it in GitHub Desktop.
Save uwang/b9db3972a6a4c037abe9fc564f610ef4 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
$("ul.nav").find("li").each(function () {
var isCurrent = false;
$(this).find("a").each(function() {
// console.log($(this).attr("href") + "," + location.pathname);
if ($(this).attr("href") === location.pathname) {
isCurrent = true;
}
});
if (isCurrent) {
$(this).addClass("active");
} else {
$(this).removeClass("active");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment