Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. DOMTokenList
  4. keys()

DOMTokenList: keys() 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⁩.

Thekeys() method of theDOMTokenList interfacereturns aniterator allowing to go through all keys contained in this object.The keys are unsigned integers.

Syntax

js
keys()

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 then retrieve an iterator containing the keys usingkeys(),then iterate through those keys using afor...of loop,writing each one to the<span>'sNode.textContent.

First, the HTML:

html
<span></span>

Now the #"span");const classes = span.classList;const iterator = classes.keys();for (let value of iterator) { span.textContent += `(${value}) `;}

The output looks like this:

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp