The item() method of a NamedNodeMap returns the Attr at a numeric index, or null if the index is out of range (MDN). You usually call it on element.attributes.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call map.item. Start with this line.
JavaScript
namedNodeMap.item(index)
Call
What it does
namedNodeMap.item(index)
Primary signature.
map.item(...)
Call with the arguments your case needs.
Built into the browser. Call item(...) on a NamedNodeMap — no import required.
Library declarations
JavaScript
namedNodeMap.item(index)
Parameters
Parameter
Description
index
Required. number. Zero-based position in the map
Return Value
Return Value
Description
*
Node when in range; null when not
JavaScript Examples
Example 1 — MDN Sample
Read attribute names with item() and bracket notation.
item → position. Useful when walking every attribute in order.
getNamedItem → name. Better when you already know the attribute name.
Out of range → null.item(99) does not throw (MDN).
Always guard. Check for null before reading .name / .value.
Compatibility
Browser Support
NamedNodeMap.item() is Baseline Widely available (MDN: across browsers since July 2015). Safe to use without a polyfill in modern teaching and production code.
✓ Baseline · Widely available
item()
Returns the Attr at a numeric index — or null if out of range. Available on element.attributes in all major browsers.
98%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
NamedNodeMap.item()Excellent
Bottom line: Use freely when looping attributes. Prefer getNamedItem(name) when you already know the attribute name.
Frequently Asked Questions
It returns the Attr at the given numeric index, or null if the index is greater than or equal to the map’s length (MDN).
No. MDN marks NamedNodeMap.item() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes when i is a number. MDN notes that myMap[i] is equivalent to myMap.item(i). A string key like map["id"] uses name lookup instead.
item(index) finds an attribute by position (0, 1, 2…). getNamedItem(name) finds an attribute by its name string.
item() returns null when index is greater than or equal to attributes.length.
When you need to walk every attribute in order — often in a for loop with map.length.