Remove the class attribute node from an <h1> element:
Click the button to remove the class attribute node from the h1 element.
<!DOCTYPE html> <html> <head> <style> .democlass {//from w ww . j av a2 s. c o m color: red; } </style> </head> <body> <h1 class="democlass">Hello World</h1> <button onclick="myFunction()">Test</button> <script> function myFunction() { var elmnt = document.getElementsByTagName("H1")[0]; var attr = elmnt.getAttributeNode("class"); elmnt.removeAttributeNode(attr); } </script> </body> </html>
The removeAttributeNode()
method removes the attribute from an element, and returns the removed attribute, as an Attr Node object.
The removeAttribute()
method removes the attribute with the specified name.
The removeAttributeNode()
method removes the specified Attr object.
The removeAttribute()
method has no return value, while this method returns the removed attribute, as an Attr object.
element.removeAttributeNode(attributenode);
Parameter Values
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
The removeAttributeNode()
returns An Attr object, representing the removed attribute node