getNamedItem (W3C DOM Core method)

Version Depr. Static
DOM1 No No
Browser support (more…)
IE6+ FF1.5+ SA1.3+ OP9+
Full Full Full Full


var attr = document.documentElement.attributes.getNamedItem('xmlns');

The example above retrieves a node called xmlns, from the attributes collection of the documentElement. If it exists in the collection, the attr variable will be a reference to that node, otherwise it will be null.

That example could also be written using the array syntax:

var attr = document.documentElement.attributes['xmlns'];

However in some cases an implementation might not support that syntax (for example Safari 2 in HTML, and Internet Explorer in XML, do not support the shortcut key syntax for accessing members of the attributes collection).


name (DOMString) required

The nodeName of the node to retrieve.


Get a node with the specified name from a NamedNodeMap.

Return value

A node (of any type) with the specified name; or null if it doesn't identify a node in the map.


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
Partial Full Full Full Full Full Full Full Full Full Full
Tip: getNamedItem is more reliable than array syntax

Apart from IE 5.5, this method is better supported for accessing members of a NamedNodeMap than the array syntax, therefore the use of this method should be preferred.

Internet Explorer 5.5 in HTML doesn't implement this method (it returns undefined).

User-contributed notes

There are no comments yet.

Related Products