The getNamedItem() method of a NamedNodeMap returns the Attr for a given name, or null if it is missing (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.getNamedItem. Start with this line.
JavaScript
namedNodeMap.getNamedItem(name)
Call
What it does
namedNodeMap.getNamedItem(name)
Primary signature.
map.getNamedItem(...)
Call with the arguments your case needs.
Built into the browser. Call getNamedItem(...) on a NamedNodeMap — no import required.
Library declarations
JavaScript
namedNodeMap.getNamedItem(name)
Parameters
Parameter
Description
name
Required. string. Attribute name to find (e.g. "id", "class")
Return Value
Return Value
Description
*
Node when found; null when missing
JavaScript Examples
Example 1 — MDN Sample
Read a present attribute and check a missing name with brackets.
getNamedItem → Attr or null. Useful when you need the node.
getAttribute → string or null. Simpler when you only need the value.
Values match when present.attr.value equals the string from getAttribute.
Always guard null. Missing names return null — do not read .value blindly.
Compatibility
Browser Support
NamedNodeMap.getNamedItem() 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
getNamedItem()
Returns the Attr for a given attribute name — or null if missing. 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.getNamedItem()Excellent
Bottom line: Use freely in modern apps. Prefer getAttribute() when you only need a string value; use getNamedItem() when you need the Attr node.
Frequently Asked Questions
It returns the Attr node for the given attribute name, or null if that name is not on the map (MDN).
No. MDN marks NamedNodeMap.getNamedItem() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
Most often from element.attributes — a live map of every Attr node on the element.
Yes. MDN notes that bracket syntax with a string key is equivalent to getNamedItem(name).
getNamedItem() returns an Attr node (or null). getAttribute() returns the attribute value as a string (or null).
Yes. If the attribute is missing, getNamedItem() returns null — always check before reading .name or .value.