HTML DOMTokenList item() Method
- Previous Page forEach()
- Next Page keys()
- Go Back to the Previous Level HTML DOMTokenList
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;
Example 2
Get the first item in the list:
let item = list.item(0);
Example 3
The result is the same:
let item = list[0];
Syntax
domtokenlist.item(index)or simply: domtokenlist[index]
Parameter
Parameter | Description |
---|---|
index |
Required. The index of the marker in the list. 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
domtokenlist.item() is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 10-11 | Support | Support | Support | Support |
Related Pages
- Previous Page forEach()
- Next Page keys()
- Go Back to the Previous Level HTML DOMTokenList