I am trying to have my bootstrap site dynamically apply the active class to the current pages link.
Home | Questions | Login/Register | View | New
The questions page has multi pages within it so site.com/questions/index & site.com/questions/new for example. The link is for site.com/questions/index
I have my javscript adding the active class to the questions/index link but not to questions/new as I would like it to.
var url = window.location;
// Will only work if string in href matches with location
$('ul.nav a[href="'+ url +'"]').parent().addClass('active');
// Will also work for relative and absolute hrefs
$('ul.nav li').filter(function() {
return this.href == url;
}).parent().addClass('active');
Have some Help?