Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get my specific menu to make the active element have a different color
    text
    copied!<p>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. </p> <p>The jsFiddle is: <a href="http://jsfiddle.net/2bhnQ/1/" rel="nofollow">http://jsfiddle.net/2bhnQ/1/</a></p> <p>My code is as follows:</p> <pre><code>&lt;div class="navbar navbar-inverse navbar-static-top"&gt; &lt;div class="navbar-inner"&gt; &lt;div class="container"&gt; &lt;a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse" href="#"&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;/a&gt; &lt;a class="brand" href="index.php"&gt;HOME&lt;/a&gt; &lt;div class="nav-collapse"&gt; &lt;ul class="nav"&gt; &lt;li class="dropdown"&gt; &lt;a href="people.php" class="dropdown-toggle" data-toggle="dropdown"&gt;People&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="people.php"&gt;All&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#staff"&gt;Staff&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#grad"&gt;Graduate Students&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#undergrad"&gt;Undergraduate Students&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#visitors"&gt;Visitors and Affiliates&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#interns"&gt;Interns&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="people.php#alumni"&gt;InfoLab Alumni&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="dropdown"&gt; &lt;a href="publications.php" class="dropdown-toggle" data-toggle="dropdown"&gt;Publications&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="publications.php"&gt;All&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="publications.php#start-and-omnibase"&gt;START and Omnibase&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="publications.php#question-answering"&gt;Question Answering&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="publications.php#semantic"&gt;The Semantic Web&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="publications.php#other"&gt;Other Publications&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="start-system.php"&gt;How START works&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>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.)</p> <pre><code>$(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"); }) }) </code></pre> <p>As a novice programmer in my first month on the job, any help is greatly appreciated. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload