Skip to content

Instantly share code, notes, and snippets.

@dhunmoon
Created February 1, 2017 16:01
Show Gist options
  • Save dhunmoon/f09bf12ff78eee61f565de8641c75581 to your computer and use it in GitHub Desktop.
Save dhunmoon/f09bf12ff78eee61f565de8641c75581 to your computer and use it in GitHub Desktop.
JS: Make Navigation Active Javascript
$(function () {
setNavigation();
});
function setNavigation() {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
$(".nav a").each(function () {
var href = $(this).attr('href');
if (path.substring(0, href.length) === href) {
$(this).closest('li').addClass('active');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment