Bootstrap menu change li active class on click

前端 未结 6 1510
予麋鹿
予麋鹿 2021-02-05 09:12

I have the following menu by bootstrap

HTML

6条回答
  •  清歌不尽
    2021-02-05 09:56

        $(".ul li").on("click", function() {
            $(this).siblings().removeClass('active');
            $(this).addClass("active");
        });
    

    This is the solution that worked for me. I declared this to become active and remove the active class and also adding the .siblings() method that allows you to search for the siblings of the li elements in the document.

提交回复
热议问题