Name
Attr — an attribute of a document element
Availability
DOM Level 1 Core
Inherits from/Overrides
Node → Attr
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 ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.