Created
October 11, 2020 22:04
-
-
Save fhdalikhan/95476ee0e6ab4d55a9ff50eb1b761642 to your computer and use it in GitHub Desktop.
ADD CLASS TO ACTIVE ANCHOR THROUGH JS
This file contains hidden or 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
// ADD CLASS TO ACTIVE ANCHOR THROUGH JS | |
$(function() { | |
var url = window.location.href; | |
// Will only work if string in href matches with location | |
$('.Topnav a[href="'+ url +'"]').addClass('active'); | |
// Will also work for relative and absolute hrefs | |
$('.Topnav a').filter(function() { | |
return this.href == url; | |
}).addClass('active'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment