The Attr interface represents an attribute in an
Element
object. Typically the allowable values for the attribute are defined in a document type definition.
The attribute's effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute's effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute's effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that the
Node.nodeValue
attribute on the
Attr
instance can also be used to retrieve the string version of the attribute's value(s).
Although
Attr
objects inherit the
Node
interface, they are not considered part of the document tree and hence the
Node
attributes
Node.parentNode
,
Node.previousSibling
, and
Node.nextSibling
have a null value for them.
In XML, where the value of an attribute can contain entity references, the child nodes of the
Attr
node may be either
Text
or
EntityReference
nodes. Because the DOM Core is not aware of attribute types, it treats all attribute values as simple strings, even if the DTD or schema declares them as having tokenized types.
Note that this object is implemented and supported by the web browser and results of its use may vary.