Element.attributes is a read-only instance property that returns a live NamedNodeMap of all attribute nodes on an element. Learn how to list names and values, how it differs from an Array, and when to use helpers like hasAttributes()—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
NamedNodeMap
04
Items
Attr nodes
05
Status
Baseline widely
06
Live?
Yes
Fundamentals
Introduction
HTML attributes like id, class, and contenteditable store extra information on a tag. In JavaScript, each of those becomes an Attr node.
element.attributes gives you a live map of every attribute currently registered on that element—useful for debugging, cloning metadata, or walking all names at once.
Prefer getAttribute() / setAttribute() when you know the name. Use attributes when you need to inspect all of them.
Concept
Understanding the Property
MDN: the Element.attributes property returns a live collection of all attribute nodes registered to the specified node. It is a NamedNodeMap, not an Array, so it has no Array methods, and Attr indexes may differ among browsers.
Read-only property — you read the map; mutate attributes via DOM APIs.
NamedNodeMap — key/value style access to Attr nodes.
Live — updates when attributes are added or removed.
Baseline — widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
attributes
Value
A NamedNodeMap object containing the element’s Attr nodes.
Item
Detail
Type
NamedNodeMap
Access
Read-only property (map contents change via attribute APIs)
Element.attributes is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.attributes
Read-only — live NamedNodeMap of Attr nodes on the element.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported (legacy NamedNodeMap)
Yes
attributesBaseline
Bottom line: Use attributes to inspect all Attr nodes. Prefer getAttribute for a known name. Iterate with for...of, or convert with Array.from when you need array methods.
Wrap Up
Conclusion
attributes is your live window into every attribute on an element. Loop with for...of, look up with getNamedItem, and remember it is a NamedNodeMap—not an array.
Live NamedNodeMap of Attr nodes—inspect every name and value.
5
Core concepts
📄01
Get only
on Element
Kind
📝02
NamedNodeMap
not Array
Type
🔍03
Attr list
name + value
Use
✅04
Baseline
widely available
Status
🎯05
for...of
best loop
Tip
❓ Frequently Asked Questions
It returns a live NamedNodeMap of all Attr nodes registered on the element — each entry has a name and value.
No. MDN marks Element.attributes as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It is a NamedNodeMap, not an Array. It has no Array methods like map or forEach. Use for...of, or Array.from(el.attributes) when you need array helpers.
Yes. If you add or remove attributes later, the same NamedNodeMap object reflects those changes.
Call el.hasAttributes(), or check el.attributes.length > 0.
Use el.getAttribute("id"), or el.attributes.getNamedItem("id") to get the Attr node.
Did you know?
Boolean attributes like contenteditable still appear in attributes. Their value may be an empty string even though the attribute is present.