在此示例中,有两个段落元素,其ID为
para 和
para1 属于同一类
jtp 。在这里,我们将删除这些段落元素的
class 属性。我们必须单击给定的
HTML按钮才能看到效果。
<!DOCTYPE html> <html> <head> <title> The removeAttribute Method </title> <style> .jtp { color: red; background-color: yellow; } </style> </head> <body> <p> Welcome to the lidihuo.com </p> <p> Example of the removeAttribute() Method </p> <p id = "para" class = "jtp"> This is a paragraph element. </p> <p id = "para1" class = "jtp"> This is second paragraph element. </p> <button onclick = "fun()"> Click me! </button> <script> function fun() { document.getElementById("para").removeAttribute("class"); document.getElementById("para1").removeAttribute("class"); } </script> </body> </html>