DOMTokenList: values() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.
Thevalues() method of theDOMTokenList interfacereturns aniteratorallowing the caller to go through all values contained in theDOMTokenList.The individual values are strings.
In this article
Syntax
values()Parameters
None.
Return value
Returns aniterator.
Examples
In the following example we retrieve the list of classes set on a<span> element as aDOMTokenList usingElement.classList. We when retrieve an iterator containing the valuesusingvalues(), then iterate through those values using afor...of loop,writing each one to the<span>'sNode.textContent.
First, the HTML:
<span></span>Now the #"span");const classes = span.classList;const iterator = classes.values();for (const value of iterator) { span.textContent += `(${value}) `;}
The output looks like this: