HTML DOM Element removeAttributeNode() method
- Previous Page removeAttribute()
- Next Page removeChild()
- Go Back to the Previous Level HTML DOM Elements Object
Definition and usage
removeAttributeNode()
method removes the attribute from the element and returns Attribute object.
Difference between removeAttribute() and removeAttributeNode()
removeAttribute()
method deletes the attribute and does not return any value.
removeAttributeNode()
method delete Attr object, and return the removed object.
The result will be the same.
Alternative solution:
Use removeAttribute() Method Easier.
See also:
Reference manual:
Tutorial:
Instance
Example 1
Remove the class attribute node from the first <h1> element:
const element = document.getElementsByTagName("H1")[0]; const attr = element.getAttributeNode("class"); element.removeAttributeNode(attr);
Example 2
Remove the href attribute node from the link:
const element = document.getElementById("myAnchor"); const attr = element.getAttributeNode("href"); element.removeAttributeNode(attr);
Syntax
element.removeAttributeNode(oldAttr)
Parameter
Parameter | Description |
---|---|
oldAttr | Required. The attribute node to be deleted. |
Return Value
Type | Description |
---|---|
Object | Represents the Attr object of the attribute that has been deleted. |
Thrown
Exception | Description |
---|---|
NO_MODIFICATION_ALLOWED_ERR | The current element is read-only and attributes cannot be deleted. |
NOT_FOUND_ERR | oldAttr Not the attribute of the current element. |
Description
This method will remove (and return) the Attr node from the current element's attribute collection. If the DTD has set a default value for the attribute to be deleted, this method will add a new Attr node representing this default value.
Tip:Use removeAttribute() Method Replacing this method is often simpler.
Browser Support
element.removeAttributeNode()
It is a DOM Level 1 (1998) feature.
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page removeAttribute()
- Next Page removeChild()
- Go Back to the Previous Level HTML DOM Elements Object