HTML DOMTokenList keys() Method

Definition and Usage

The keys() method returns an iterator (Iterator) with keys from the DOMTokenList.

Example

Example 1

Get DOMTokenList from "demo":

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

Try it yourself

Example 2

List the keys in the list:

const list = document.body.childNodes;
for (let x of list.keys()) {
  text += x;
}

Try it yourself

Example 3

List the values in the list:

const list = document.body.childNodes;
for (let x of list.values()) {
  text += x;
}

Try it yourself

Syntax

domtokenlist.keys()

Parameters

No parameters.

Return Value

Type Description
Object Iterator object containing the keys of the list.

Browser Support

domtokenlist.keys() 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.keys().

Related Pages

length Property

item() Method

add() Method

remove() Method

toggle() Method

forEach() Method

entries() Method

values() Method

DOMTokenList Object