Name

Attr: an attribute of a document element — DOM Level 1 Core: 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 is explicitly specified in the document source or set by a script; false if the attribute is 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( ) or getAttributeNodeNS( ) methods of the Element interface.

The value of an attribute is represented by the descendant nodes of an Attr node. In HTML documents, an Attr node always has a single Text node child, and the value property provides a shortcut for reading and writing the value of this child node.

The XML grammar allows XML documents to have attributes that consist ...

Get JavaScript: The Definitive Guide, 5th 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.