Get the name of the first attribute of a <button> element:
The result of x could be:
More "Try it Yourself" examples below.
The item() method returns the node at the specified index in a NamedNodeMap, as a Node object.
The nodes are sorted as they appear in the source code, and the index starts at 0.
Note: There are two ways to access an attribute node at the specified index in a NamedNodeMap:
You can use whatever method you like, however, the most common method is [index].
Tip: Use the length property to return the number of nodes in a NamedNodeMap object.
Method | |||||
---|---|---|---|---|---|
item() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
index | Number | Required. The index of the node in the NamedNodeMap you want to return |
Return Value: | A Node object, representing the attribute node at the specified index. Note: Returns null if the index number is out of range |
---|---|
DOM Version | Core Level 1 |
Change the value of a <button> element's second attribute: