How to toggle class using jquery if else statement?

前端 未结 5 1494
渐次进展
渐次进展 2021-01-20 17:14

I want to toggle class using jquery If Else statement for specified conditions.

My Html with default css class=\"horizontal\"

5条回答
  •  遥遥无期
    2021-01-20 17:27

    You can use the switch in toggleClass().

    A Boolean value to determine whether the class should be added or removed.

    $('#foo-bar').toggleClass('horizontal', myvar==layout1)
                 .toggleClass('vertical', myvar==layout2);
    

提交回复
热议问题