mpgn mpgn - 1 year ago 89
HTML Question

Set link of my navbar active with bootstap

I try to set active the element of my navbar when i click on the button.

My navbar is like that :


But when i click on the "a" for exemple, the "G" remains active.

My code is like that :

<div class="navbar span8" id="navbar">
<div class="navbar-inner">
<ul class="nav">
<li><a href="#a">A</a></li>
<li><a href="#b">B</a></li>
<li><a href="#c">C</a></li>
<li><a href="#d">D</a></li>
<li><a href="#e">E</a></li>
<li><a href="#f">F</a></li>

To set a class active the code is :

<li class="active"><a href="#f">F</a></li>

How can i do that with jQuery ?

Answer Source

You can set it active like this..

$('.nav li').click(function(){
    $('.nav li').removeClass('active');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download