DOMTokenList
The DOMTokenList interface represents a set of space-separated tokens. Such a set is returned by Element.classList or HTMLLinkElement.relList, and many others.
Indexable
[index: number]: string
Methods
[iterator]()
iterator: ArrayIterator<string>;
Returns
ArrayIterator<string>
add()
add(...tokens): void;
The add() method of the DOMTokenList interface adds the given tokens to the list, omitting any that are already present.
Parameters
| Parameter | Type |
|---|---|
...tokens | string[] |
Returns
void
contains()
contains(token): boolean;
The contains() method of the DOMTokenList interface returns a boolean value — true if the underlying list contains the given token, otherwise false.
Parameters
| Parameter | Type |
|---|---|
token | string |
Returns
boolean
entries()
entries(): ArrayIterator<[number, string]>;
Returns
ArrayIterator<[number, string]>
forEach()
forEach(callbackfn, thisArg?): void;
Parameters
| Parameter | Type |
|---|---|
callbackfn | (value, key, parent) => void |
thisArg? | any |
Returns
void
item()
item(index): string | null;
The item() method of the DOMTokenList interface returns an item in the list, determined by its position in the list, its index.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
string | null
keys()
keys(): ArrayIterator<number>;
Returns
ArrayIterator<number>
remove()
remove(...tokens): void;
The remove() method of the DOMTokenList interface removes the specified tokens from the list.
Parameters
| Parameter | Type |
|---|---|
...tokens | string[] |
Returns
void
replace()
replace(token, newToken): boolean;
The replace() method of the DOMTokenList interface replaces an existing token with a new token. If the first token doesn't exist, replace() returns false immediately, without adding the new token to the token list.
Parameters
| Parameter | Type |
|---|---|
token | string |
newToken | string |
Returns
boolean
supports()
supports(token): boolean;
The supports() method of the DOMTokenList interface returns true if a given token is in the associated attribute's supported tokens. This method is intended to support feature detection.
Parameters
| Parameter | Type |
|---|---|
token | string |
Returns
boolean
toggle()
toggle(token, force?): boolean;
The toggle() method of the DOMTokenList interface removes an existing token from the list and returns false. If the token doesn't exist it's added and the function returns true.
Parameters
| Parameter | Type |
|---|---|
token | string |
force? | boolean |
Returns
boolean
toString()
toString(): string;
Returns
string
values()
values(): ArrayIterator<string>;
Returns
ArrayIterator<string>
Properties
length
readonly length: number;
The read-only length property of the DOMTokenList interface is an integer representing the number of objects stored in the object.
value
value: string;
The value property of the DOMTokenList interface is a stringifier that returns the value of the list serialized as a string, or clears and sets the list to the given value.