HTML DOM removeAttribute() Method
Example
Remove the class attribute from an <h1> element:
document.getElementsByTagName("H1")[0].removeAttribute("class");
Before removing the attribute:
Hello World
After removing the attribute:
Hello World
Try it Yourself »
Definition and Usage
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.
Browser Support
Method | |||||
---|---|---|---|---|---|
removeAttribute() | Yes | Yes | Yes | Yes | Yes |
Syntax
element.removeAttribute(attributename)
Parameter Values
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to remove |
Technical Details
Return Value: | No return value |
---|---|
DOM Version | Core Level 1 Element Object |
More Examples
Example
Remove the href attribute from an <a> element:
document.getElementById("myAnchor").removeAttribute("href");
Before removing the attribute:
After removing the attribute:
Go to w3schools.com
Try it Yourself »
Related Pages
HTML Tutorial: HTML Attributes
HTML DOM Reference: hasAttribute() Method
HTML DOM Reference: getAttribute() Method
HTML DOM Reference: setAttribute() Method