Element.getAttributeNames() is an instance method that returns every attribute name on an element as an array of strings. Learn how to pair it with getAttribute(), when you get an empty array, qualified namespace names, and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Returns
string[]
03
Empty
[] if none
04
Pair with
getAttribute()
05
vs
.attributes
06
Status
Baseline widely
Fundamentals
Introduction
Sometimes you need every attribute on an element—not just one. Older code often looped over element.attributes, a live NamedNodeMap of Attr nodes. That works, but MDN recommends getAttributeNames() plus getAttribute() as a lighter pattern.
The method takes no parameters and always returns an array. Zero attributes means [], not null.
💡
Beginner tip
getAttributeNames() gives you names only. To read values, loop and call el.getAttribute(name) for each name.
Element.getAttributeNames() is Baseline Widely available (MDN: across browsers since October 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.getAttributeNames()
List every attribute name on an element as a string array.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerNot supported · Use attributes fallback
No
getAttributeNames()Excellent
Bottom line: Use getAttributeNames() to enumerate attribute names, then getAttribute() for values. Prefer this over attributes when you only need names and want a lighter loop.
Wrap Up
Conclusion
Element.getAttributeNames() gives you every attribute name on an element in one array. Pair it with getAttribute() to read values efficiently, and remember [] when nothing is set.
Mutate the array expecting DOM changes (re-call instead)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.getAttributeNames()
All attribute names in one array.
5
Core concepts
📝01
Returns
string[]
API
📄02
Empty
[]
None set
✍️03
Values
getAttribute
Pair
✅04
Baseline
widely available
Status
⚡05
vs attrs
lighter
MDN
❓ Frequently Asked Questions
It returns an array of strings — the names of all attributes on the element. 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. Use 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 (e.g. xlink:href), the prefix is included in the returned name. Attributes in a namespace without a prefix return just the local name, with no namespace indication (MDN).
Did you know?
MDN recommends getAttributeNames() with getAttribute() as a memory-efficient alternative to looping element.attributes when you only need name/value pairs—not full Attr nodes.