Skip to content

Instantly share code, notes, and snippets.

@craiger522
Last active December 23, 2015 00:59
Show Gist options
  • Save craiger522/6557520 to your computer and use it in GitHub Desktop.
Save craiger522/6557520 to your computer and use it in GitHub Desktop.
Jquery: Get current page and apply class to .nav li
<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