NamedNodeMap : Object

Collection of nodes accessible by name or position.

Browser/User Agent Support

IEMozillaNetscapeOperaSafariNetscapte
no1.0+6.0+7.0+1.0+no

Constructors

ConstructorIEMozillaNetscapeOperaSafariNetscapte
Collection of nodes accessible by name or position.
no1.0+6.0+7.0+1.0+no
 

Properties

PropertyIEMozillaNetscapeOperaSafariNetscapte
Number of nodes in this node map.
no1.0+6.0+7.0+1.0+no
 

Methods

MethodIEMozillaNetscapeOperaSafariNetscapte
Returns the specified node.
no1.0+6.0+7.0+1.0+no
 
Returns the node identified by the given name and XML namespace URI.
no1.0+6.0+7.0+1.0+no
 
Returns the node at the specified index number.
no1.0+6.0+7.0+1.0+no
 
Removes the specified node from the map.
no1.0+6.0+7.0+1.0+no
 
Remove the node identified by the given name and XML namespace URI.
no1.0+6.0+7.0+1.0+no
 
Add the supplied node to the map.
no1.0+6.0+7.0+1.0+no
 
Add the supplied node defined with XML namespaces to the map
no1.0+6.0+7.0+1.0+no
 

Remarks

This object is used to represent collections of nodes that can be accessed by name. NamedNodeMap is similar to the NodeList object, except its contents are accessed by the value of a node's Node.nodeName property, rather than by a numeric index. This is equivilant in concept to a "hash" or "associative array" in other languages.

This object is mainly used in the Node object to represent XML Node.attributes, though is also used in a few other places within the DOM.

References

NodeList

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

Constructor Detail

NamedNodeMap NamedNodeMap()

Collection of nodes accessible by name or position.

Visibility
internal

Property Detail

Number length - read only

Number of nodes in this node map.

Remarks
Returns the number of nodes stored within this node map. This can be used in conjunction with the item method for enumerating through the list of nodes.
Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

Method Detail

getNamedItem(String name) : static Node

Returns the specified node.

StringnameName of the node.

Using getNamedItem

var element = document.Document.getElementById('linkElement');
                    var linkTarget = element.Node.attributes.getNamedItem('href');
Remarks

Retrieves a node from the object referenced by the given name. Like most methods within this object, the name of each node contained within a node map is derived from that node's Node.nodeName property.

This is the DOM1-compatible method for retrieving items from a node map and as such does not understand XML Namespaces. If you need to manipulate node maps containing namespaces, use this method's companion function getNamedItemNS.

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

getNamedItemNS(String namespaceURI, String localName) : static Node

Returns the node identified by the given name and XML namespace URI.

StringnamespaceURINamespace URI of the node to retrieve.
StringlocalNameLocal name of the node to retrieve.

Using getNamedItemNS

var element = document.Document.getElementById('menubar');
                    var xulNS = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
                    var attr = element.Node.attributes.getNamedItemNS(xulNS, 'datasources');
Remarks

Retrieves a node from the object referenced by the given name and XML namespace URI. Like most methods within this object, the name of each node contained within a node map is derived from that node's Node.nodeName property. This method breaks the node's name out into it's two-part Namespace-enabled node name for elements that support it, namely Attr and Element.

This is the DOM2 method for retrieving items from a node map, though it isn't necessary for retrieving nodes that either don't use namespaces or for nodes that don't understand the concept of namespace URIs, like Text. If you need to retrieve nodes without namespaces, use this method's companion function getNamedItem.

Availability

HTML DOM Level 2 | W3C

item(Number index) : static Node

Returns the node at the specified index number.

NumberindexIndex number to retrieve.

Using item

if (nodeMap.length > 0) {
                    for (var idx = 0; idx < nodeMap.length; idx++) {
                    var node = nodeMap.item(idx);
                    // Do something with this node
                    }
                    }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/item.html

Remarks

Returns the node contained within this object at the given index number. It is important to note that node maps do not keep it's nodes in any specific order. As such, the item method and length property are only provided to enumerate through a map's contents.

See Also

NodeList

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

removeNamedItem(String name) : static Node

Removes the specified node from the map.

StringnameName of the node to remove from the map

Remarks

Removes a node from the map matching the given name. This method returns the indicated node after it has been removed.

If this map represents the Node.attributes bound to an Element and the XML document has a default attribute defined for the attribute being removed, then a new entry for this attribute's default value will immediately re-appear in this node map.

This is the DOM1-compatible method for removing items from a node map and as such does not understand XML Namespaces. If you need to manipulate node maps containing namespaces, use this method's companion function removeNamedItemNS.

Throws
Raises a NOT_FOUND_ERR error if the given name is not found in this map.
Raises a NO_MODIFICATION_ALLOWED_ERR error if this node map object is read-only.
See Also

Element.removeAttribute

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

removeNamedItemNS(String namespaceURI, String localName) : static Node

Remove the node identified by the given name and XML namespace URI.

StringnamespaceURINamespace URI of the node to remove.
StringlocalNameLocal name of the node to remove.

Remarks
Removes a node from the map matching the given name. This method is identical in operation to the removeNamedItem method in this object, with the exception that this method is aware of XML Namespaces. If you are removing a node from the map that is defined with an XML namespace, then you should be using this method.
Throws
Raises a NOT_FOUND_ERR error if the given name is not found in this map.
Raises a NO_MODIFICATION_ALLOWED_ERR error if this node map object is read-only.
Availability

HTML DOM Level 2 | W3C

setNamedItem(Node arg) : static Node

Add the supplied node to the map.

NodeargNode to add to the map.

Remarks

Adds the given node to the node map. Like most methods within this object, the name of each node contained within a node map is derived from that node's Node.nodeName property. If an entry already exists in the map with the name of the new node being added, the old node is removed and is subsequently returned from this method call. In the event that there is no other node with the same name however, then null is returned.

Because you don't have the capability of setting explicit names for a node you add to a map, it is possible for name conflicts when two nodes have the same name. Since certain types of DOM Nodes always return the same name (see Node.nodeName), as in Text nodes for instance, then it is only possible to store one node per node type in a named map.

This is the DOM1-compatible method for setting items in a node map and as such does not understand XML Namespaces. If you need to manipulate node maps containing namespaces, use this method's companion function setNamedItemNS.

Throws
Raises a WRONG_DOCUMENT_ERR error if the supplied node was created in a different document from the current map object.
Raises a NO_MODIFICATION_ALLOWED_ERR error if this node is read-only.
Raises an INUSE_ATTRIBUTE_ERR error if the supplied node is an Attr object that is already bound to an Element.

See Also

Element.setAttribute

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

setNamedItemNS(Node arg) : static Node

Add the supplied node defined with XML namespaces to the map

NodeargNode to add to the map.

Remarks
Adds the given node to the node map. This method is identical in operation to the setNamedItem method in this object, with the exception that this method is aware of XML Namespaces. If you are adding a node to the map that is defined with an XML namespace, then you should be using this method.
Throws
Raises a WRONG_DOCUMENT_ERR error if the supplied node was created in a different document from the current map object.
Raises a NO_MODIFICATION_ALLOWED_ERR error if this node is read-only.
Raises an INUSE_ATTRIBUTE_ERR error if the supplied node is an Attr object that is already bound to an Element.

Availability

HTML DOM Level 2 | W3C