HTML DOMTokenList item()

❮ The DOMTokenList Object

Examples

Get a DOMTokenList from "demo":

let list = document.getElementById("demo").classList;
Try it Yourself »

Get the first item in the list:

let item = list.item(0);
Try it Yourself »

This produces the same result:

let item = list[0];
Try it Yourself »

Description

The item() method returns the token at a specified index in a DOMTokenList.

There are two ways to access a token at a specified index:

list.item(index)
or
list[index]

The easiest and most common method is [index].




Syntax

domtokenlist.item(index)
or simply:
domtokenlist[index]

Parameters

Parameter Description
index Required.
The index of the token in the list.
The tokens are sorted as they appear in the document.
The index starts at 0.

Return Value

Type Description
StringThe token at the specified index.
null if the index is out of range.

Browser Support

domtokenlist.item() is supported in all browsers:

Chrome IE Edge Firefox Safari Opera
Yes 10-11 Yes Yes Yes Yes

❮ The DOMTokenList Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.