HTML DOMTokenList forEach() Method

Definition and Usage

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

Example

Example 1

Get DOMTokenList from "demo":

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

Try it yourself

Example 2

Execute function for each tag:

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 tag.
currentValue Required. The current marked value.
index Optional. The current marked index.
arr Optional. The current marked DOMTokenList.
thisValue

Optional. Default undefined.

As the value passed to the function of 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