Twitter Bootstrap. Active menu item marking
14,404
Solution 1
You just have to add "active" in your li like :
<li class="active">
<a href="#"></a>
</li>
Solution 2
Add a class of the active
to the li
http://twitter.github.com/bootstrap/components.html#navbar
Author by
Wolter
Updated on June 04, 2022Comments
-
Wolter almost 2 years
I use standart twitter bootstrap menu:
<ul class="nav nav-pills"> <li><a href="#">...</a></li> <li><a href="#">...</a></li> </ul>
How to mark active menu item?
-
Wolter about 11 yearsIt's mark only one marked <li>, not current. It's static, not active.
-
Wolter about 11 yearsIt's mark only one marked <li>, not current. It's static, not active.
-
Chris about 11 yearsJust add some javascript to make it active
-
ashley about 11 yearsthen add a class to it anyway:
.marked { background: red; }
then put<li class="marked"></li>
or in css declare:.nav li:first-child { background: red; }
-
Wolter about 11 yearsYou mean something from standart Bootstrap js tools?
-
Chris about 11 yearsNot necessarily, you can just add an id or whatever to identify each li and change their class to "active" when this page is loaded
-
Chris about 11 yearsdocument.getElementById("idOfCurrentli").setAttribute("class", "active");
-
Wolter about 11 yearsAnd how to define idOfCurrentli :) ?
-
Chris about 11 yearsIn your html : <li id="homePage"><a href="#">...</a></li> And then in the js of this page : document.getElementById("homePage").setAttribute("class", "active");