Element: removeAttributeNode() method
{{ APIRef("DOM") }}
The removeAttributeNode() method of the {{domxref("Element")}} interface removes the specified {{domxref("Attr")}} node from the element.
If you don't need to inspect the attribute node before removing it, you can use the {{domxref("Element.removeAttribute()")}} method instead.
Syntax
removeAttributeNode(attributeNode)
Parameters
attributeNode- : The attribute node to remove from the element.
Return value
The attribute node that was removed.
Exceptions
NotFoundError{{DOMxRef("DOMException")}}- : Thrown when the element's attribute list does not contain the attribute node.
Examples
// Given: <div id="foo" lang="en-US" />
const d = document.getElementById("foo");
const dLang = d.getAttributeNode("lang");
d.removeAttributeNode(dLang);
// lang is now removed: <div id="foo" />
Notes
If the removed attribute has a default value, it is immediately replaced. The replacing attribute has the same namespace URI and local name, as well as the original prefix, when applicable.
There is no removeAttributeNodeNS method; the
removeAttributeNode method can remove both namespaced attributes and
non-namespaced attributes.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("Document.createAttribute()")}}
- {{domxref("Element.getAttributeNode()")}}
- {{domxref("Element.setAttributeNode()")}}
这篇文档对你有帮助吗?
谢谢你的反馈!