HTML DOMTokenList item() Method

Definition and Usage

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

There are two ways to access the marker at the specified index:

list.item(index)

or

list[index]

The simplest and most commonly used method is [index]。

Instance

Example 1

Get DOMTokenList from "demo":

let list = document.getElementById("demo").classList;

Try it yourself

Example 2

Get the first item in the list:

let item = list.item(0);

Try it yourself

Example 3

The result is the same:

let item = list[0];

Try it yourself

Syntax

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

Parameter

Parameter Description
index

Required. The index of the marker in the list.

The markers are sorted in the order they appear in the document.

The index starts from 0.

Return value

Type Description
String The marker at the specified index.
null If the index is out of range.

Browser support

All browsers support domtokenlist.item():

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

Related pages

length property

add() method

remove() method

toggle() method

forEach() method

entries() method

keys() method

values() method

DOMTokenList object