运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> .myStyle { background-color: coral; padding: 16px; } .anotherClass { text-align: center; font-size: 25px; } .thirdClass { text-transform: uppercase; } </style> <body> <h1>The DOMToken Object</h1> <h2>The contains() and remove() Methods</h2> <p>Click "Remove" to remove "anotherClass", if "myDIV" has a"myStyle" class.</p> <button onclick="myFunction()">Remove</button> <div id="myDIV" class="myStyle anotherClass thirdClass"> <p>I am myDIV.</p> </div> <script> function myFunction() { const element = document.getElementById("myDIV"); if (element.classList.contains("myStyle")) { element.classList.remove("anotherClass"); } } </script> </body> </html>