HTML DOMTokenList forEach() Method

Definition and Usage

The forEach() method executes a callback function for each marker (token) in the DOMTokenList.

Example

Example 1

Get DOMTokenList from "demo":

let list = document.getElementById("demo").classList;

Try It Yourself

Example 2

Execute a function for each marker:

list.forEach(
  function(token, index) {
    text += index + " " + token;
  }
);

Try It Yourself

Syntax

nodelist.forEach(function(currentValue, index, arr) thisValue)

Parameters

Parameters Description
function() Required. The function to be run for each marker.
currentValue Required. The current marked value.
index Optional. The current marked index.
arr Optional. The current marked DOMTokenList.
thisValue

Optional. Default undefined.

The 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 by all browsers:

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Internet Explorer 11 (and earlier versions) does not support domtokenlist.forEach().

Related Pages

length Property

item() Method

add() Method

remove() Method

toggle() Method

replace() Method

entries() Method

keys() Method

values() Method

DOMTokenList Object