Collection of nodes accessible by name or position.
Platform Support
Constructors
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
- Visibility
- internal
|
Properties
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 item
method for enumerating through the list of nodes.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Functions
Returns the specified node.
|
Show Details |
no |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
String |
name |
Name of the node. |
Returns
-
Using getNamedItemvar 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
|
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
-
Using getNamedItemNSvar 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
|
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
-
Using itemif (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
|
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
- 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
|
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
- 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
|
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
- 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
|
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
- 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 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