Availability
DOM Level 1 Core
Inherits from/Overrides
Node

Properties
readonly String name
The name of
the attribute.
readonly Element ownerElement [DOM Level 2]
The
Element object that contains this attribute, or
null if the Attr object is not currently
associated with any Element.
readonly boolean specified
true if the
attribute was explicitly specified in the document source or set by a
script. false if the attribute was not explicitly
specified but a default value is specified in the document's
DTD.
String value
The value of
the attribute. When reading this property, the attribute value is
returned as a string. When you set this property to a string, it
automatically creates a Text node that contains the same text and
makes that Text node the sole child of the Attr object.
Description
An
Attr object represents an attribute of an Element node. Attr objects
are associated with Element nodes but are not directly part of the
document tree (and have a null
parentNode property). You can obtain an Attr
object through the attributes property of the Node
interface or by calling the getAttributeNode(
) method of the Element interface.
Attr objects are nodes, and the value of an Attr is represented by
the child nodes of the Attr node. In HTML documents, this is simply a
single Text node. In XML documents, however, Attr nodes may have both
Text and EntityReference children. The value
property provides a shortcut for reading and writing the value of an
attribute as a String.
In most cases, the easiest way to work with element attributes is
with the getAttribute( ) and
setAttribute( ) methods of the Element interface.
These methods use strings for attribute names and values and avoid
the use of Attr nodes altogether.
See Also
Element
Passed to
Element.removeAttributeNode( ), Element.setAttributeNode( ),
Element.setAttributeNodeNS( )
Returned by
Document.createAttribute( ), Document.createAttributeNS( ),
Element.getAttributeNode( ), Element.getAttributeNodeNS( ),
Element.removeAttributeNode( ), Element.setAttributeNode( ),
Element.setAttributeNodeNS( )