Path: blob/main/website/awaited-dom/DOMTokenList.md
1029 views
AwaitedDOM / DOMTokenList
DOMTokenList
interface represents a set of space-separated tokens. Such a set is returned by Element.classList
, HTMLLinkElement.relList
, HTMLAnchorElement.relList
, HTMLAreaElement.relList
, HTMLIframeElement.sandbox
, or HTMLOutputElement.htmlFor
. It is indexed beginning with 0
as with JavaScript Array
objects. DOMTokenList
is always case-sensitive.Properties
.length W3C {#length}
Is an integer
representing the number of objects stored in the object.
Type: Promise<number>
.value W3C {#value}
A stringifier property that returns the value of the list as a string
.
Type: Promise<string>
Methods
.add*(...tokens)* W3C {#add}
Adds the specified token
(s) to the list.
Arguments:
tokens
string
. Astring
representing the token (or tokens) to add to thetokenList
.
Returns: Promise<void>
.contains*(token)* W3C {#contains}
Returns true
if the list contains the given token
, otherwise false
.
Arguments:
token
string
. Astring
representing the token you want to check for the existance of in the list.
Returns: Promise<boolean>
.entries*()* W3C {#entries}
Returns an iterator
, allowing you to go through all key/value pairs contained in this object.
Returns: Promise<>
.forEach*()* W3C {#forEach}
Executes a provided callback
function once per DOMTokenList
element.
Returns: Promise<>
.item*(index)* W3C {#item}
Returns the item in the list by its index
, or undefined
if index
is greater than or equal to the list's length
.
Arguments:
index
number
. Astring
representing the index of the item you want to return.
Returns: Promise<string>
.keys*()* W3C {#keys}
Returns an iterator
, allowing you to go through all keys of the key/value pairs contained in this object.
Returns: Promise<>
.remove*(...tokens)* W3C {#remove}
Removes the specified token
(s) from the list.
Arguments:
tokens
string
. Astring
representing the token you want to remove from the list. If the string is not in the list, no error is thrown, and nothing happens.
Returns: Promise<void>
.replace*(token, newToken)* W3C {#replace}
Replaces token
with newToken
.
Arguments:
token
string
. Astring
representing the token you want to replace.newToken
string
. Astring
representing the token you want to replaceoldToken
with.
Returns: Promise<boolean>
.supports*(token)* W3C {#supports}
Returns true
if a given token
is in the associated attribute's supported tokens.
Arguments:
token
string
. Astring
containing the token to query for.
Returns: Promise<boolean>
.toggle*(token, force?)* W3C {#toggle}
Removes token
from the list if it exists, or adds token
to the list if it doesn't. Returns a boolean indicating whether token
is in the list after the operation.
Arguments:
token
string
. Astring
representing the token you want to toggle.force
boolean
. Aboolean
that, if included, turns the toggle into a one way-only operation. If set tofalse
, thentoken
will only be removed, but not added. If set totrue
, thentoken
will only be added, but not removed.
Returns: Promise<boolean>
.values*()* W3C {#values}
Returns an iterator
, allowing you to go through all values of the key/value pairs contained in this object.