Skip to content

Instantly share code, notes, and snippets.

@miyamae
Last active October 3, 2015 18:47
Show Gist options
  • Select an option

  • Save miyamae/428b495b85956bd808ec to your computer and use it in GitHub Desktop.

Select an option

Save miyamae/428b495b85956bd808ec to your computer and use it in GitHub Desktop.
Iimplement the bootstrap navbar active class with JS
$(function() {
$('a').each(function() {
if (window.location.pathname.indexOf($(this).attr('href')) === 0) {
$(this).parent().addClass('active');
}
});
});
$ ->
$('a').each ->
if window.location.pathname.indexOf($(@).attr('href')) == 0
$(@).parent().addClass('active')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment