add(); addClass(); 添加class
    remove(); removeClass();移除class

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>Document</title>
    7. <style>
    8. .current{
    9. color:red;
    10. }
    11. </style>
    12. </head>
    13. <body>
    14. <!--
    15. add(); addClass();
    16. remove(); removeClass();
    17. -->
    18. <p id="app">hello world</p>
    19. <button id="btn">移除class</button>
    20. <script>
    21. var app = document.getElementById("app");
    22. var btn = document.getElementById("btn");
    23. app.onclick = function(){
    24. this.classList.add("current")
    25. }
    26. btn.onclick = function(){
    27. app.classList.remove("current")
    28. }
    29. </script>
    30. </body>
    31. </html>

    1.PNG