DOM Methods

DOMTokenList.item()

Returns the token at a zero-based position, or null if absent. Use length to determine valid indices. Unlike an index into a string, each returned value is a whole token. For a classList, it reflects the order of distinct class names in the attribute. Example result: active.

Formal Syntax & Structure

html syntaxhtml
list.item(index)

Parameters & Attributes

NameTypeDescription
indexnumberZero-based token position.

Return Value

string | null

String token at the requested index, or null.

Working Example

Example Snippethtml
<p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  const el = document.createElement("div"); el.className = "card active"; const list = el.classList;  result.textContent = list.item(1);  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference