I know that this question has been answered before, but I can't figure out how to do it with my code because of the amount of div's and the amount of classes. How can I make the active page have a different background color. I'm using a responsive twitter bootstrap (2) frame so you have to stretch the viewing window out to see all the tabs at the top.
The jsFiddle is: http://jsfiddle.net/2bhnQ/1/
My code is as follows:
<div class="navbar navbar-inverse navbar-static-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse" href="#">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.php">HOME</a>
<div class="nav-collapse">
<ul class="nav">
<li class="dropdown">
<a href="people.php" class="dropdown-toggle" data-toggle="dropdown">People<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="people.php">All</a></li>
<li><a href="people.php#staff">Staff</a></li>
<li><a href="people.php#grad">Graduate Students</a></li>
<li><a href="people.php#undergrad">Undergraduate Students</a></li>
<li><a href="people.php#visitors">Visitors and Affiliates</a></li>
<li><a href="people.php#interns">Interns</a></li>
<li><a href="people.php#alumni">InfoLab Alumni</a></li>
</ul>
</li>
<li class="dropdown">
<a href="publications.php" class="dropdown-toggle" data-toggle="dropdown">Publications<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="publications.php">All</a></li>
<li><a href="publications.php#start-and-omnibase">START and Omnibase</a></li>
<li><a href="publications.php#question-answering">Question Answering</a></li>
<li><a href="publications.php#semantic">The Semantic Web</a></li>
<li><a href="publications.php#other">Other Publications</a></li></ul>
</li>
<li>
<a href="start-system.php">How START works</a></li>
</ul>
</div>
</div>
</div>
I've tried doing something like this, but it didn't work. (This is just an answer from another stackoverflow, so I guessed it would be helpful, but I can use $(location).attr('href') or any other option if it helps.)
$(document).ready(function(){
alert(window.location.pathname);
$(".navbar navbar-inverse navbar-static-top .navbar-inner .container .nav-collapse .nav li a").each(function(){
if($(this).attr("href")==window.location.pathname)
$(this).addClass("active");
}) })
As a novice programmer in my first month on the job, any help is greatly appreciated. Thanks.