removeNamedItemNS (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM2 | No | No |
| IE7 | FF1.5+ | SA3+ | OP9+ |
|---|---|---|---|
| None | Buggy | Full | Buggy |
- Returns
Node- Throws
NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
Example
var attrs = document.documentElement.attributes;
var removed = attrs.removeNamedItemNS('http://www.w3.org/1999/xhtml', 'lang');
The example above saves the attributes
collection of the documentElement, and
then attempts to remove an item with the name lang in
the XML namespace from that collection, saving the removed item to the
removed variable.
If that item exists in the
collection then it will be removed and saved to the
removed variable, otherwise this method should throw a
DOMException (code 8: NOT_FOUND_ERR).
Arguments
- namespace (
DOMString) required The
namespaceURIof the node to remove. A value ofnullmeansno namespace.- namespace (
DOMString) required The
localNameof the node to remove.
Description
Remove a node with the
specified name and namespace URI from a NamedNodeMap.
If the removed node is an attribute
that's attached to an element, and the attribute has a default in this
document type, a new attribute with the default value should be
automatically created (as well as the corresponding namespaceURI, localName
and prefix, if applicable).
Return value
The node that's been removed;
or null if no such node exists in the map.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| None | None | None | Buggy | Buggy | Buggy | Buggy | Buggy | Full | Buggy | Buggy |
Internet Explorer doesn't implement this method (it returns undefined).
Opera does not throw an
exception when attempting to remove an item that doesn't exist; the
operation silently fails and the method returns null.
In Safari 1.3 and 2 attributes inherit a namespace from their owning element, therefore this method will match members of an attribute collection with no explicit namespace if the namespace argument matches the default.
Additionally,
Safari 1.3 cannot see the
xml prefix, so an xml:lang
attribute will be treated as a lang attribute, and
matched only if the namespace argument is
http://www.w3.org/1999/xhtml (even when the document
isn't any flavour of HTML); other XML attributes which have no HTML analog
(such as xml:space) will be matched if the
namespace argument is null or an empty string. In
Safari 2 this is only the case for an
xml:lang attribute — other XML attributes are
matched correctly, although they are also still matched if the namespace
argument is null or an empty string.
In
Firefox an empty-string namespace is treated
the same as a null namespace (ie. it's taken to mean
no namespace, when it should be treated as a real
namespace URI); conversely Opera only
understands an empty string to mean no namespace, it doesn't understand
null; the only browser to get this right is
Safari 3.
Since namespaces are an XML construct, it's only reasonable to judge the behavior of this method in terms of XML (either on HTML pages in XHTML mode1, or pure XML). The behavioral variations of browsers in HTML mode2 are documented here for interest and reference, but the support summary table above does not consider this behavior.
All supported browsers in HTML mode
behave essentially the same as they do in XHTML mode, except that they
don't recognise namespaces at all. (So
Opera only matches items in no namespace if
the namespace argument is an empty string;
Firefox only matches items in no namespace
if the namespace argument is null or an empty
string; Safari 3 only matches items in no
namespace if the namespace argument is null;
Safari 1.3 and 2 only match items in no
namespace if the namespace argument matches the default.)
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.