HTML DOM item() method
Example
Return the first attribute name of the button element:
document.getElementsByTagName("BUTTON")[0].attributes.item(0).nodeName;
Output result:
onclick
Try it »
Definition and Usage
The item() method returns the node at the specified index in the node list.
Syntax:
document.getElementsByTagName("BUTTON")[0].attributes.item(0);
Another way of writing:
document.getElementsByTagName("BUTTON")[0].attributes[0];
Browser support





All major browsers support the item() method
Syntax
namednodemap
.item(
index
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| index | Number | Required. The specified node index in the node list. |
Return Value
| Type | Description |
|---|---|
| Node object | The node at the specified index |
Technical Details
| DOM version | Core Level 1 |
|---|
Attribute object