# NamedNodeMap : Object
Return to: HTML DOM Level 2 index

Collection of nodes accessible by name or position.

## Platform Support

IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | ---
no | 1.0+ | 6.0+ | 7.0+ | 1.0+

## Constructors

Constructor | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
NamedNodeMap Constructor() : NamedNodeMap Collection of nodes accessible by name or position. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

### NamedNodeMap() : NamedNodeMap

Collection of nodes accessible by name or position.

Returns

NamedNodeMap |

Visibility
  internal

## Properties

Property | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
length : Number Number of nodes in this node map. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

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

  HTML DOM Level 1|HTML DOM Level 2|W3C

## Functions

Method | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
static getNamedItem(String name) : Node Returns the specified node. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

String | name | Name of the node.

Returns

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 <property>Node.nodeName</property> property.

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

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

static getNamedItemNS(String namespaceURI, String localName) : Node Returns the node identified by the given name and XML namespace URI. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

String | namespaceURI | Namespace URI of the node to retrieve.
String | localName | Local name of the node to retrieve.

Returns

Node |

  ### 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 <property>Node.nodeName</property> 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 <method>getNamedItem</method>.

Availability

  HTML DOM Level 2|W3C

static item(Number index) : Node Returns the node at the specified index number. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

Number | index | Index number to retrieve.

Returns

Node |

  ### 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 <method>item</method> method and <property>length</property> property are only provided to enumerate through a map's contents.

See Also

  NodeList

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

static removeNamedItem(String name) : Node Removes the specified node from the map. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

String | name | Name of the node to remove from the map

Returns

Node |

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 <property>Node.attributes</property> 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 <glossary>XML Namespaces</glossary>. If you need to manipulate node maps containing namespaces, use this method's companion function <method>removeNamedItemNS</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.
See Also

  Element.removeAttribute

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

static removeNamedItemNS(String namespaceURI, String localName) : Node Remove the node identified by the given name and XML namespace URI. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

String | namespaceURI | Namespace URI of the node to remove.
String | localName | Local name of the node to remove.

Returns

Node |

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

static setNamedItem(Node arg) : Node Add the supplied node to the map. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

Node | arg | Node to add to the map.

Returns

Node |

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 <property>Node.nodeName</property> 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.

  <warning>

  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 <property>Node.nodeName</property>), as in `Text` nodes for instance, then it is only possible to store one node per node type in a named map.

  </warning>

  This is the DOM1-compatible method for setting items in a node map and as such does not understand <glossary>XML Namespaces</glossary>. If you need to manipulate node maps containing namespaces, use this method's companion function <method>setNamedItemNS</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`.
See Also

  Element.setAttribute

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

static setNamedItemNS(Node arg) : Node Add the supplied node defined with XML namespaces to the map | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

Node | arg | Node to add to the map.

Returns

Node |

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

## 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 <property>Node.nodeName</property> 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 <property>Node.attributes</property>, though is also used in a few other places within the DOM.

## References

NodeList

## Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

text_javascript aptana_docs