Create a bare element. No attributes in the markup or via JS.
Call the method. Result is always an array.
Check .length. Zero means no attributes.
Not null. Empty list ≠ missing return value.
Compatibility
Browser Support
Element.getAttributeNames() is Baseline Widely available on MDN (across browsers since October 2018). It is not Deprecated, Experimental, or Non-standard.
✓ Baseline Widely available
Element.getAttributeNames()
List attribute names as a string array. Widely available since 2018.
2018+Widely available
Google Chrome61+
Supported
Mozilla Firefox45+
Supported
Apple Safari10.1+
Supported
Microsoft Edge17+
Supported
Opera48+
Supported
Internet ExplorerNot supported
Unavailable
getAttributeNames()Baseline
Bottom line: Safe for modern browsers. Prefer with getAttribute() over walking Element.attributes for simple dumps.
Frequently Asked Questions
It returns an array of strings — the names of all attributes on the element (MDN). If there are no attributes, it returns an empty array.
No. MDN marks Element.getAttributeNames() as Baseline Widely available (across browsers since October 2018). It is not Deprecated, Experimental, or Non-standard.
An array of attribute name strings. Pair with getAttribute(name) in a loop to read each value.
getAttributeNames() returns only name strings. Element.attributes is a live NamedNodeMap of Attr nodes. MDN recommends getAttributeNames() with getAttribute() as a more memory-efficient alternative.
No. Call el.getAttributeNames() with no arguments.
If an attribute has a namespace prefix (for example xlink:href), the prefix is included. Attributes in a namespace without a prefix return just the local name, with no namespace indication (MDN).