How to change active class while click to another link in bootstrap use jquery?

前端 未结 13 1260
刺人心
刺人心 2020-11-30 05:32

I have a html as sidebar, and use Bootstrap.

13条回答
  •  半阙折子戏
    2020-11-30 05:35

    $(".nav li").click(function() {
        if ($(".nav li").removeClass("active")) {
            $(this).removeClass("active");
        }
        $(this).addClass("active");
    });
    

    This is what I came up with. It checks if the "li" element has the class of active, if it doesn't it skips the remove class part. I'm a bit late to the party, but hope this helps. :)

提交回复
热议问题