Remove the class attribute from an <h1> element:
Before removing the attribute:
After removing the attribute:
The removeAttribute() method removes the specified attribute from an element.
The difference between this method and the removeAttributeNode() method is that the removeAttributeNode() method removes the specified Attr object, while this method removes the attribute with the specified name. The result will be the same. Also this method has no return value, while the removeAttributeNode() method returns the removed attribute, as an Attr object.
Tip: Use the getAttribute() method to return the value of an attribute of an element.
Tip: Use the setAttribute() method to add an attribute to an element.
Method | |||||
---|---|---|---|---|---|
removeAttribute() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to remove |
Return Value: | No return value |
---|---|
DOM Version | Core Level 1 Element Object |
Remove the href attribute from an <a> element:
Before removing the attribute:
After removing the attribute:
HTML Tutorial: HTML Attributes
HTML DOM Reference: hasAttribute() Method
HTML DOM Reference: getAttribute() Method
HTML DOM Reference: setAttribute() Method