Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2014 16:45
Show Gist options
  • Save anonymous/2302275a160a4cceca99 to your computer and use it in GitHub Desktop.
Save anonymous/2302275a160a4cceca99 to your computer and use it in GitHub Desktop.
Simple jQuery script to add Bootstrap navigation's active class automatically.
$(document).ready(function() {
var path = window.location.pathname;
var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];
if (filename == "index") {
$( "#index" ).addClass( "active" );
}
else if (filename == "profile") {
$( "#profile" ).addClass( "active" );
}
else if (filename == "recommended_site") {
$( "#recommended-site" ).addClass( "active" );
}
else {
console.log("Cannot find matching ID");
}
})
@arahansa
Copy link

우아아아아 ㅠㅠ ㅋㅋ 감사합니다. ㅋㅋ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment