Toggle active class in nav bar with JQuery

前端 未结 7 1049
醉酒成梦
醉酒成梦 2020-12-06 05:50
  • Home
7条回答
  •  青春惊慌失措
    2020-12-06 06:41

    $(function() {
       $("li").click(function() {
          // remove classes from all
          $("li").removeClass("active");
          // add class to the one we clicked
          $(this).addClass("active");
       });
    });
    

    It would be wise to give meaningful classes to the

  • 's so you can properly select just those, but you get the idea.

提交回复
热议问题