Attr : Node

Represents the attributes of an Element object.

Constructors

ConstructorIEMozillaNetscapeOperaSafariNetscapte
Represents the attributes of an Element object.
 

Properties

PropertyIEMozillaNetscapeOperaSafariNetscapte
Name of the attribute object.
4.0+1.0+6.0+7.0+1.0+no
 
Parent node that the attribute is attached to.
4.0+1.0+6.0+7.0+1.0+no
 
If true, specifies that the attribute was explicitly created.
4.0+1.0+6.0+7.0+1.0+no
 
Value of the attribute.
4.0+1.0+6.0+7.0+1.0+no
 

Remarks

Attributes are properties of Elements and do not have their own identities. Although an Attr is a descendant of a Node, an Attr is not placed in a parentNode, nextSibling or previousSibling, and its own instances of those properties are null. Additionally, an Attr objects may only be a child of an Element object.

Set the value of an attribute either via the DOM, from a source document, or from a DTD or other XML Schema. If a declaration for an attribute exists that defines a default value, and the attribute in question does not exist, the attribute will be automatically added with the given value. Usually, however, an attribute does not exist until it is explicitly added.

References

Element

Availability

HTML DOM Level 2 | W3C

Constructor Detail

Attr Attr()

Represents the attributes of an Element object.

Visibility
internal

Property Detail

String name - read only

Name of the attribute object.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes.html

Remarks
Due to the nature of DOM Element attributes, the name value must be unique across attributes attached to the same element node.
Availability

W3C | HTML DOM Level 2

Element ownerElement - read only

Parent node that the attribute is attached to.

Remarks
Because attributes are meaningless unless they are bound to an Element, this property allows you to find the node that an attribute is attached to. If this attribute is not yet attached to a node, the value of this property is set to null.
Availability

W3C | HTML DOM Level 2

Boolean specified - read only

If true, specifies that the attribute was explicitly created.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes.html

Remarks

If true, indicates that this attribute value was explicitly set from a source XML document or via a DOM method call. Otherwise, the specified property is false.

For example, if a document has an element definition with a "width" attribute with a default value of "3", the specified property for the Attr of the element is set to false when the document loads. If the value of the is subsequently changed, this property will change to true. You can only revert the specified property back to its original value by deleting the attribute from its parent node so that the DTD recreates the default attribute.

Availability

W3C | HTML DOM Level 2

String value

Value of the attribute.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes.html

Remarks

Returns and sets the value of the attribute as a String. Replaces entity references with their values. In addition to methods for retrieving Attr objects, the Element object has methods for accessing the value of an attribute without having to deal directly with the Attr object.

Availability

W3C | HTML DOM Level 2