Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- var array = activePage.split('/');
- var page = '/' + array[1];
- $('.nav li a').each(function () {
- var currentPage = stripTrailingSlash($(this).attr('href'));
- if (page == currentPage) {
- $(this).parent().addClass('active');
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement