Remove the class attribute node from the first <h1> element:
const element = document.getElementsByTagName("H1")[0];
const attr = element.getAttributeNode("class");
element.removeAttributeNode(attr);
Try it Yourself »
Remove the href attribute node from a link:
const element = document.getElementById("myAnchor");
const attr = element.getAttributeNode("href");
element.removeAttributeNode(attr);
Try it Yourself »
The removeAttributeNode()
method removes an attribute from an element.
The removeAttributeNode()
method returns an Attribute object.
The removeAttribute()
method removes an attribute, and does not have a return value.
The removeAttributeNode()
method removes an Attr object, and returns the removed object.
The result will be the same.
element.removeAttributeNode(
node)
Parameter | Description |
attributenode | Required. The attribute node to remove. |
Type | Description |
Object | An Attr object representing the removed attribute. |
element.removeAttributeNode()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!