I am a new ASP.NET Web Forms developer and trying to use Twitter Bootstrap with the Master Page. I am struggling with setting navbar item as active when user selects it. I creat
following code works if I have subpages:
$(document).ready(function () {
$('.navbar .nav').find('.active').removeClass('active');
var url = window.location.toString();
var u = url.substring(0, url.lastIndexOf("/")).toString();
$('.navbar .nav li a').each(function () {
var hr = this.href.substring(0, this.href.lastIndexOf('/')).toString();
if ((u == hr) || (u.indexOf(hr) > -1))
{
$(this).parent().addClass('active');
return false;
}
});
// Deactivation to manually add items you have with href = "#" example:
$('#liSalir').removeClass('active');
});