MVC with Bootstrap Navbar - Set Selected Item to Active

后端 未结 7 1504
抹茶落季
抹茶落季 2020-12-13 10:05

I\'m learning Bootstrap and can\'t get the selected item into an \"active\" state. The active state remains on the default item. The newly selected/clicked item changes to

相关标签:
7条回答
  • 2020-12-13 11:06

    I believe you have the selection backward. You're adding the class, then removing it from the siblings, and I think doing the remove second is causing the issue. Can you try reversing this to be:

    <script type="text/javascript">
    
        $(function () {
            $('.navbar-nav li').click(function () {
                $(this).siblings().removeClass('active');
                $(this).addClass('active');
            });
        });
    
    </script>
    
    0 讨论(0)
提交回复
热议问题