name (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM1 | No | No | Yes |
| IE5.5+ | FF3+ | SA3+ | OP9+ |
|---|---|---|---|
| Full | Buggy | Full | Buggy |
Example
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.
Description
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.
Compatibility
| 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).
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.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.