Last active
October 23, 2019 17:19
-
-
Save acbrent25/0bc77348b6bdeb856f4eeadd509c26e7 to your computer and use it in GitHub Desktop.
Add Active Class to Current Page #navigation
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
// Get Full URL | |
var href = window.location.href; | |
// Get everything before last '/' | |
var baseUrl = href.substr(0, href.lastIndexOf('/')); | |
// Get everything after last '/' | |
var currentPage = href.substr(href.lastIndexOf('/') + 1); | |
// Add Class active to the link if on current page | |
$('a[href="'+ baseUrl + '/' + currentPage + '"]').addClass('active'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment