The removeNamedItemNS() method of a NamedNodeMapremoves a namespaced Attr node by namespace URI and localName. Learn the MDN XML DOMParser example, why the URI is not the prefix, and how it compares with removeNamedItem() and removeAttributeNS()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Removed Attr
03
Args
URI + local
04
Not prefix
namespace URI
05
Use case
XML / SVG
06
Status
Baseline widely
Fundamentals
Introduction
getNamedItemNS() reads a namespaced attribute from element.attributes. removeNamedItemNS() is the mirror—it deletes that namespaced attribute and returns the removed Attr node.
MDN’s example parses XML with ob:one="test" and xmlns:ob="http://www.example.com/ob", then calls removeNamedItemNS("http://www.example.com/ob", "one") to drop the attribute.
💡
Beginner tip
MDN warns: the first argument is the namespace URI (the full URL), not the prefix (ob). Pass "http://www.example.com/ob", not "ob".
Concept
Understanding the removeNamedItemNS() Method
An instance method on NamedNodeMap that removes a namespaced attribute by URI and local name.
namespace — string URI of the attribute’s namespace (not the prefix).
localName — local part of the attribute name (without prefix).
Returns — the removed Attr node.
Exception — thrown when no matching namespaced attribute exists (MDN).
Common source — element.attributes on XML/SVG nodes.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Call the method on a NamedNodeMap (usually from element.attributes):
NamedNodeMap.removeNamedItemNS() 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.removeNamedItemNS()
Removes the namespaced Attr for a namespace URI and localName—or throws if not found.
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.removeNamedItemNS()Excellent
Bottom line: Call map.removeNamedItemNS(namespaceURI, localName) on element.attributes for XML and SVG namespaced attribute removal.
Wrap Up
Conclusion
NamedNodeMap.removeNamedItemNS() removes namespaced attributes by namespace URI and localName, returning the removed Attr. Use it on XML and SVG nodes, remember the URI is not the prefix, and prefer removeAttributeNS() when you only need to delete a value.
Wrap in try/catch when the attribute might be missing
Use getNamedItemNS first if you need to verify existence
Prefer removeAttributeNS for simple deletion
❌ Don’t
Pass the xmlns prefix where MDN expects a URI
Use removeNamedItemNS for ordinary HTML id / class
Assume it returns null like getNamedItemNS
Forget that missing namespaced attrs throw
Rely on removeNamedItem("ob:one") alone in portable XML
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about removeNamedItemNS()
Namespaced Attr removal by URI + localName.
5
Core concepts
🔗01
Returns
Removed Attr
API
⚙️02
Args
uri, local
Params
⚠️03
Not prefix
use URI
MDN
📄04
Missing
throws
Error
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
It removes the Attr node matching a namespace URI and localName from the map and returns that removed Attr. On XML/SVG elements, element.attributes.removeNamedItemNS(uri, 'one') drops the namespaced attribute.
No. MDN marks NamedNodeMap.removeNamedItemNS() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
The namespace URI (a full URL string), not the xmlns prefix. MDN warns: namespace is the URI, not the prefix like ob in ob:one.
The removed Attr node. You can still read .localName, .value, and .namespaceURI after removal.
MDN documents an exception: the method throws if there is no attribute with the given namespace and local name (typically NotFoundError).
removeNamedItemNS() on attributes returns the removed Attr. element.removeAttributeNS(namespace, localName) works on the element and returns undefined.
Did you know?
MDN’s removeNamedItemNS() demo removes ob:one with removeNamedItemNS("http://www.example.com/ob", "one")—the URI and local name, not the ob prefix—then confirms attrMap["ob:one"] is gone.