Skip to content

Instantly share code, notes, and snippets.

@acbrent25
Last active October 23, 2019 17:19
Show Gist options
  • Save acbrent25/0bc77348b6bdeb856f4eeadd509c26e7 to your computer and use it in GitHub Desktop.
Save acbrent25/0bc77348b6bdeb856f4eeadd509c26e7 to your computer and use it in GitHub Desktop.
Add Active Class to Current Page #navigation
// 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