Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM item() method

HTML DOM item() method

Attribute Object Reference Attribute object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 Reference Attribute object