Represents an attribute or property of an HTML element as an object.
Members
The attribute object has these types of members:
Methods
The attribute object has these methods.
| Method | Description |
|---|---|
| appendChild |
Appends an element as a child to the object. |
| cloneNode |
Copies a reference to the object from the document hierarchy. |
| compareDocumentPosition |
Compares the position of two nodes in a document. |
| hasChildNodes |
Returns a value that indicates whether the object has children. |
| insertBefore |
Inserts an element into the document hierarchy as a child node of a parent object. |
| isDefaultNamespace |
Indicates whether or not a namespace is the default namespace for a document. |
| isEqualNode |
Determines if two nodes are equal. |
| isSameNode |
Determines if two node references refer to the same node. |
| isSupported |
Returns a value indicating whether or not the object supports a specific DOM standard. |
| lookupNamespaceURI |
Gets the URI of the namespace associated with a namespace prefix, if any. |
| lookupPrefix |
Gets the namespace prefix associated with a URI, if any. |
| normalize |
Merges adjacent DOM objects to produce a normalized document object model. |
| removeChild |
Removes a child node from the object. |
| removeNode |
Removes the object from the document hierarchy. |
| replaceChild |
Replaces an existing child element with a new child element. |
| replaceNode |
Replaces the object with another element. |
| swapNode |
Exchanges the location of two objects in the document hierarchy. |
Properties
The attribute object has these properties.
| Property | Description |
|---|---|
|
Retrieves the number of immediate child nodes of the current element or a zero if the element does not contain any child nodes. childElementCount does not return all child nodes, only child nodes that are nodeType =1, or element nodes. | |
|
Returns a reference to the constructor of an object. | |
|
Sets or retrieves a value indicating whether arbitrary variables can be created within the object. | |
|
Gets a reference to the first child in the childNodes collection of the object. | |
|
Retrieves a reference to the first child element, or null if there are no child elements. | |
|
Gets a reference to the last child in the childNodes collection of an object. | |
|
Retrieves a reference to the last child element or null if there are no child elements. | |
|
Retrieves the local name of the fully qualified XML declaration for a node. | |
|
Sets or retrieves the name of the object. | |
|
Retrieves the namespace URI of the fully qualified XML declaration for a node. | |
|
Retrieves a reference to the sibling element that immediately follows or null if the element does not have any sibling elements that follow it. | |
|
Retrieves a reference to the next child of the parent for the object. | |
|
Gets the name of a particular type of node. | |
|
Retrieves the type of the requested node. | |
|
Gets or sets the value of a node. | |
|
Retrieves the document object associated with the node. | |
|
Retrieves the element that owns the attribute. | |
|
Retrieves the parent object in the document hierarchy. | |
|
Retrieves the local name of the fully qualified XML declaration for a node. | |
|
Retrieves a reference to the immediately preceding sibling element or null if the element does not have any preceding siblings. | |
|
Gets a reference to the previous child of the parent for the object. | |
|
Gets a value that indicates whether an attribute is explicitly given a value. | |
|
Sets or retrieves the text content of an object and any child objects. | |
|
Gets or sets the value of the object. |
Standards information
There are no standards that apply here.
Remarks
The attribute object is accessible through the attributes collection.
A valid attribute or property can be any Dynamic HTML (DHTML) property or event that applies to the object, or an expando.
Examples
This example uses the attribute object to create a list of attributes that are specified.
<script type="text/javascript">
function fnFind(){
var oList = document.getElementById("myList");
for(var i=0;i<oList.attributes.length;i++){
if(oList.attributes[i].specified){
console.log(oList.attributes[i].nodeName + " = "
+ oList.attributes[i].nodeValue);
}
}
}
</script>
<ul onclick="fnFind()">
<li id = "myList" accesskey = "l">List Item 1
</ul>
Build date: 11/28/2012