HTML DOMTokenList item() Method

Definition and Usage

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

There are two ways to access the mark 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

Result is the same:

let item = list[0];

Try it yourself

Syntax

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

Parameter

Parameter Description
index

Required. Index of the marked list.

Tags are sorted in the order they appear in the document.

Index starts from 0.

Return Value

Type Description
String Mark 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 Attribute

add() Method

remove() Method

toggle() Method

forEach() Method

entries() Method

keys() Method

values() Method

DOMTokenList Objects