Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Represents the attributes of an Element object. | ||||||
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
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
Availability
HTML DOM Level 2 | W3C
Constructor Detail
Property Detail
String name - read only
Name of the attribute object.
-
For examples, see the quirksmode test page:
- Remarks
- Due to the nature of DOM Element attributes, the
namevalue 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 tonull. - 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:
- Remarks
-
If true, indicates that this attribute value was explicitly set from a source XML document or via a DOM method call. Otherwise, the
specifiedproperty is false.For example, if a document has an element definition with a "width" attribute with a default value of "3", the
specifiedproperty for theAttrof the element is set to false when the document loads. If the value of the is subsequently changed, this property will change totrue. You can only revert thespecifiedproperty 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:
- Remarks
Returns and sets the value of the attribute as a String. Replaces entity references with their values. In addition to methods for retrieving
Attrobjects, theElementobject has methods for accessing the value of an attribute without having to deal directly with theAttrobject.- Availability
W3C | HTML DOM Level 2
