jQuery UI switchClass() method is not working properly

后端 未结 7 2143
野的像风
野的像风 2020-12-11 15:43

jQuery UI switchClass() method doesn\'t switch class, rather it performs some undesired animations and the class remains the same as the original one when I use

相关标签:
7条回答
  • 2020-12-11 16:40

    I am guessing you want to toggle between two classes. If that is the case you can do it with toggleClass function.

     //first you start with one of the classes in html:
        <div class="foo"></div>
        //then in js you do:
        var element = ...;
        $(element).toggleClass('foo bar');
    

    This will toggle both 'foo' and 'bar'. Since foo is already present it will remove it and add bar. On the next call bar will be present so i will remove it and add foo. And so on.

    If something is not clear here is a jsfiddle example: https://jsfiddle.net/09qs86kr/1/

    0 讨论(0)
提交回复
热议问题