Web APIs

DOMTokenList.contains()

Try the free JavaScript compiler

Test exact token membership rather than a substring of the serialized class attribute. Example console output: false true.

Formal Syntax & Structure

javascript syntaxjavascript
tokens.contains(token)

Parameters & Attributes

NameTypeDescription
tokenstringExact token.

Return Value

boolean

Whether the token exists.

Working Example

Example Snippetjavascript
const p=document.createElement("p"); p.className="inactive"; console.log(p.classList.contains("active"),p.classList.contains("inactive"));
JavaScript Reference