The item() method of a NamedNodeMap returns the Attr node at a numeric index. Learn the MDN element.attributes example, how map[i] mirrors item(i), looping with length, and how index lookup differs from getNamedItem()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Attr or null
03
Arg
Numeric index
04
Alias
map[i] numeric
05
Use case
Loop all attrs
06
Status
Baseline widely
Fundamentals
Introduction
Every element exposes a live attributes collection—a NamedNodeMap. You can look up one attribute by name with getNamedItem("class"), but sometimes you need to walk every attribute in order.
That is what item(index) is for. Pass 0, 1, 2, and so on to get each Attr node. MDN also notes that map[1] (numeric bracket) calls the same logic as map.item(1).
💡
Beginner tip
Bracket notation has two meanings on a NamedNodeMap: map[0] uses item(0) (index), while map["id"] looks up by attribute name. Keep numbers and strings straight.
Concept
Understanding the item() Method
An instance method on NamedNodeMap that returns the attribute node at a zero-based position.
index — a number: 0 for the first attribute, 1 for the second, and so on.
Returns — an Attr node, or null if index ≥ length.
Bracket alias — map[i] when i is numeric (MDN).
Common source — element.attributes on any element.
Pair with — map.length to loop every attribute.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Call the method on a NamedNodeMap (usually from element.attributes):
JavaScript
namedNodeMap.item(index)
namedNodeMap[index] // numeric index only — same as item(index)
Parameters
index — non-negative integer position in the map (0-based).
Return value
An Attr at that index, or null when the index is out of range.
NamedNodeMap.item() is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
NamedNodeMap.item()
Returns the Attr at a numeric index—or null when the index is out of range.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported on NamedNodeMap (legacy DOM)
Legacy OK
NamedNodeMap.item()Excellent
Bottom line: Call map.item(index) or map[index] (numeric) on element.attributes to walk attributes by position.
Wrap Up
Conclusion
NamedNodeMap.item() returns the Attr at a numeric index, or null when the index is too large. Use it with length to loop every attribute, and remember that numeric map[i] is the same call (MDN).