Onclick Show / Hide Multiple Divs Jquery

前端 未结 5 1228
萌比男神i
萌比男神i 2021-01-22 14:24

I need to create navigation that shows / hides multiple divs.

Here is what I need to be able to do: If a user clicks on any of the \"options

5条回答
  •  生来不讨喜
    2021-01-22 14:48

    For your first trouble you can add the following two lines to your click event:

        $(".buttons .selected").removeClass("selected");
        $(this).addClass("selected"); 
    

    Or as Irrelepant says (a better way actually):

    $(this).addClass('selected').siblings().removeClass('selected');
    

提交回复
热议问题