Created
April 22, 2014 22:12
-
-
Save aklinkert/11196213 to your computer and use it in GitHub Desktop.
Marks the current active Tab by comparing urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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