HTML DOMTokenList item() Method
- Previous Page forEach()
- Next Page keys()
- Back to Top 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]
Example
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
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. 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
- Previous Page forEach()
- Next Page keys()
- Back to Top HTML DOMTokenList