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 »
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)
list[index]
The easiest and most common method is [index].
domtokenlist.item(
index)
domtokenlist[
index]
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. |
Type | Description |
String | The token at the specified index.null if the index is out of range. |
domtokenlist.item()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 10-11 | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!