name (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No Yes
Browser support (more…)
IE5.5+ FF3+ SA3+ OP9+
Full Buggy Full Buggy


var attrs = document.documentElement.attributes;

for(var i=0; i<attrs.length; i++)
  var attrname = attrs[i].name;

In the example above we create a reference to the documentElement attributes collection, then we iterate through the collection numerically and retrieve the name of each individual attribute.


The name of an Attr or DocumentType.

In the case of an Attr this is the name part of a name="value" pair. In the case of a DocumentType it's the name immediately following the DOCTYPE token, which for all flavours of HTML will be html.

For a namespaced attribute, the name property returns a qualified name1.

This property is readonly.


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
Full Full Full Full Full Buggy Buggy Buggy Full Buggy Buggy

In Opera 9.0 in HTML mode2 the name of an attribute is often returned in uppercase; a consistent pattern for when this does/doesn't occur could not be established, but appears to be related to whether that attribute has already been referred to in lower case (in which case its name is returned in lowercase, otherwise uppercase).

In Firefox 3 in HTML mode the name of a doctype is returned in uppercase.

In Safari 1.3 and 2 in XHTML mode or XML3 the name of a doctype is null (in Safari 1.3 and 2 in HTML mode the doctype property itself is null).

: The applicable node may not be available

In Internet Explorer in HTML the doctype property is null; in Internet Explorer 5.5 in HTML it's not possible to retrieve attribute nodes; however in situations where these objects are available their name always returns correctly, hence this property is considered fully supported.


1 A name comprised of the namespace prefix and localName, delimited with a colon, such as xml:lang.

2 On XHTML or HTML pages served as text/html.

3 On XHTML pages served as application/xhtml+xml.

User-contributed notes

There are no comments yet.

Related Products