Same keys. Both APIs take namespace URI + local name.
getNamedItemNS → Attr. Use when you need the node (name, URI, …).
getAttributeNS → string. Simpler when you only need the value.
Values match when present.attr.value equals the string.
Compatibility
Browser Support
NamedNodeMap.getNamedItemNS() 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
getNamedItemNS()
Returns the Attr for a namespace URI + local 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.getNamedItemNS()Excellent
Bottom line: Use freely for XML/SVG namespaces. Prefer getAttributeNS() when you only need a string; use getNamedItem() for plain HTML names.
Frequently Asked Questions
It returns the Attr for the given namespace URI and local name, or null if no matching namespaced attribute exists (MDN).
No. MDN marks NamedNodeMap.getNamedItemNS() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
A namespace URI — not the xmlns prefix. MDN warns: namespace is the URI of the namespace, not the prefix (for example use http://www.example.com/ob, not ob).
getNamedItem(name) looks up by a single name (typical HTML). getNamedItemNS(namespace, localName) needs both the namespace URI and the local name for XML/SVG attributes.
getNamedItemNS() returns an Attr node (or null). element.getAttributeNS(namespace, localName) returns the string value (or null).
When working with XML, SVG, or other markup where attributes belong to a namespace — often after parsing XML with DOMParser.