Last active
January 5, 2017 18:53
-
-
Save emaildano/577db0f9964d27fd5a6d3a8add43e441 to your computer and use it in GitHub Desktop.
Add active class to links matching current URL
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
$(function() { | |
var host = location.host; | |
var path = location.pathname; | |
var url = '//' + host + path; | |
var target = 'nav a'; | |
$(target).each(function() { | |
var $this = $(this); | |
console.log(url); | |
if($this.attr('href') == url) { | |
$this.addClass('active'); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment