jQuery toggle class

后端 未结 2 1330
猫巷女王i
猫巷女王i 2020-12-03 19:02

I\'m having trouble adding in jQuery\'s toggleClass function into the rest of my code. The page has several HTML5 audio tags on it which are controlled via jQuery. I attempt

相关标签:
2条回答
  • 2020-12-03 19:38

    I would use .addClass() and .removeClass(), as it'll clean up your code quite a bit and allow you to use CSS to perform all that layout work:

    $('thumbnail').toggle(function(){
        $('.play', this).removeClass('pausing');
        $('.play', this).addClass('playing');
    }, function(){
        $('.play', this).addClass('pausing');
        $('.play', this).removeClass('playing');
    });
    
    0 讨论(0)
  • 2020-12-03 19:48
    $('thumbnail').toggleClass('pausing playing');
    

    ToggleClass: Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.

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