Web APIs
DOMTokenList.contains()
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
| Name | Type | Description |
|---|---|---|
| token | string | Exact 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"));