HTML - DOMTokenList keys() Method



HTML DOMTokenList keys() method returns an iterator which allows us to go through all the keys contained in the token list. These keys are unsigned integer.

Syntax

domtokenlist.keys();

Parameter

This method does not accept any parameter.

Return Value

It returns an iterator.

Example of HTML DOMTokenList 'keys()' Method

The following example returns keys of tokens in the token list.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOMTokenList keys() Method
    </title>
    <style>
        .color {
            background-color: #04af2f;
            color: white;
        }
        .font {
            font-size: 40px;
        }
        .align {
            text-align: center;
        }
    </style>
</head>
<body>
    <p id="add" class="color font align">
        Welcome to Tutorials Point...
    </p>
    <button onclick="fun()">Click me</button>
    <p>Keys are :</p>
    <p id="token"></p>
    <script>
        let result = document.getElementById("token");
        function fun() {
            let x = document.getElementById("add").classList.keys();
            for(let i of x){
                result.innerHTML += i +"<br>";
            }
        }
    </script>
</body>
</html>

Supported Browsers

Method Chrome Edge Firefox Safari Opera
keys() Yes 42 Yes 16 Yes 50 Yes 10.1 Yes 29
html_dom.htm
Advertisements