Last active
December 23, 2015 00:59
-
-
Save craiger522/6557520 to your computer and use it in GitHub Desktop.
Jquery: Get current page and apply class to .nav li
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
<script type="text/javascript" charset="utf-8"> | |
$(document).ready(function(){ | |
var pathname = (window.location.pathname.match(/[^\/]+$/)[0]); | |
$('.nav li a').each(function() { | |
if ($(this).attr('href') == pathname) | |
{ | |
$(this).parent().addClass('active'); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment