HTML DOMTokenList forEach()
❮ The DOMTokenList ObjectExamples
Get a DOMTokenList from "demo":
let list = document.getElementById("demo").classList;
Try it Yourself »
Execute a function for each token:
list.forEach(
function(token, index) {
text += index + " " + token;
}
);
Try it Yourself »
function(token, index) {
text += index + " " + token;
}
);
Description
The forEach()
method executes a callback function for each token in a
DOMTokenList.
See Also:
Syntax
nodelist.forEach(function(currentValue, index, arr), thisValue)
Parameters
function()
Required.
A function to run for each token.
A function to run for each token.
currentValue
Required.
The value of the current token.
The value of the current token.
index
Optional.
The index of the current token.
The index of the current token.
arr
Optional.
The DOMTokenList of the current token.
The DOMTokenList of the current token.
thisValue
Optional. Default
A value passed to the function as its
undefined
.A value passed to the function as its
this
value.
Return Value
NONE
Browser Support
domtokenlist.forEach()
is a DOM Level 4 (2015) feature.
It is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
❮ The DOMTokenList Object