JQ 操作css

addClass() 向元素添加一个或多个class


    <div>Always believe that good things are going to happen</div>
    <p>Always believe that good things are going to happen</p>

    <script>
        $('div').addClass('one tow three');
        $('p').addClass('four');
    </script>



removeClass() 删除class


    <div class="one two three">Always believe that good things are going to happen</div>
    <p class="four five">Always believe that good things are going to happen</p>
    <script>
        $('div').removeClass();
        $('p').removeClass('four');
    </script>



toggleClass() 添加或删除切换


    <div class="one two three">Always believe that good things are going to happen</div>
    <p class="four">Always believe that good things are going to happen</p>
    <script>
        $('div').toggleClass('one css');
        $('p').toggleClass('four');
    </script>


原文地址:https://www.cnblogs.com/xiaobaiv/p/9446794.html