The Element.getAttributeNode() method returns a named attribute as an Attr node (MDN). Missing attribute → null. If you only need the string value, prefer getAttribute().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.getAttributeNode. Start with this line.
JavaScript
el.getAttributeNode(attrName)
Call
What it does
el.getAttributeNode(attrName)
Primary signature.
el.getAttributeNode(...)
Call with the arguments your case needs.
Built into the browser. Call getAttributeNode(...) on an Element — no import required.
Library declarations
JavaScript
el.getAttributeNode(attrName)
Parameters
Parameter
Description
attrName
Required. Attribute name (HTML → lowercase)
Return Value
Return Value
Description
*
Attr node, or null
JavaScript Examples
Example 1 — Read Attr.value
Get the id attribute as an Attr, then read its value.
JavaScript
const t = document.getElementById("top");
const out = document.getElementById("out");
const idAttr = t.getAttributeNode("id");
out.textContent = idAttr.value;
Use case: APIs that pass around Attr objects, not strings.
Compatibility
Browser Support
Element.getAttributeNode() is Baseline Widely available on MDN (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
✓ Baseline Widely available
Element.getAttributeNode()
Return a named attribute as an Attr node. Core DOM — available everywhere modern.
2015+Widely available
Google ChromeAll modern
Supported
Mozilla FirefoxAll modern
Supported
Apple SafariAll modern
Supported
Microsoft EdgeAll modern
Supported
OperaAll modern
Supported
Internet ExplorerSupported
Supported
getAttributeNode()Baseline
Bottom line: Safe for all modern browsers and IE. Prefer getAttribute() unless you need the Attr object.
Frequently Asked Questions
It returns the specified attribute as an Attr node object, not a plain string (MDN). Use it when you need Attr properties such as name, value, or ownerElement.
No. MDN marks Element.getAttributeNode() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
null. If no attribute matches the name, there is no Attr node to return.
getAttribute() returns a string value or null. getAttributeNode() returns an Attr object (or null) so you can read node-level details like ownerElement.
No. MDN: parentNode, previousSibling, and nextSibling are null on Attr nodes. Use ownerElement to get the element the attribute belongs to.
When you only need the attribute value as a string, getAttribute() is simpler and what most modern code uses (MDN).