Created
August 28, 2015 18:35
-
-
Save Ibochkarev/fdb0a5c4152e4870b9f4 to your computer and use it in GitHub Desktop.
Twitter Bootstrap add active class to li
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
//Active | |
var url = window.location; | |
// Will only work if string in href matches with location | |
$('ul.navbar-nav a[href="'+ url +'"]').parent().addClass('active'); | |
// Will also work for relative and absolute hrefs | |
$('ul.navbar-nav a').filter(function() { | |
return this.href == url; | |
}).parent().addClass('active'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment