简体   繁体   中英

Put active class on active nav bar in bootstrap

I have a navigation bar like this:

  <li class="active">
    <a href="{% url 'website:wedding' %}">Home</a>
    </li>

    <li><a href="/todo_list/">To-do</a></li>

    <li><a href="/budget/">Budget</a></li>

Now, even if I am on To-do navigation bar the blue effect remains on Home nav only as there is class=active . How can I make it dynamic, so that if I am on To-do, the blue effect will comes on To-do nav bar.

This should work

$(document).ready(function(){
   $('.navbar').on('click','li',function(){
      $('.navbar').find('.active').removeClass('active');
      $(this).addClass('active');
   });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM