Skip to content

Instantly share code, notes, and snippets.

@aklinkert
Created April 22, 2014 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aklinkert/11196213 to your computer and use it in GitHub Desktop.
Save aklinkert/11196213 to your computer and use it in GitHub Desktop.
Marks the current active Tab by comparing urls
/*menu handler*/
$(function(){
function stripTrailingSlash(str) {
if(str.substr(-1) == '/') {
return str.substr(0, str.length - 1);
}
return str;
}
var url = window.location.pathname;
var activePage = stripTrailingSlash(url);
$('.nav li a').each(function(){
var currentPage = stripTrailingSlash($(this).attr('href'));
if (activePage == currentPage) {
$(this).parent().addClass('active');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment