HTML - DOMTokenList values() Method



HTML DOMTokenList values() method returns an iterator allowing us to go through all values contained in the token list. Each values are strings.

Syntax

domtokenlist.values();

Parameter

This method does not take any parameter.

Return Value

It returns an iterator.

Example of HTML DOMTokenList 'values()' Method

Following example will illustarte the the use of HTML DOMTokenList 'values()' method.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOMTokenList values() Method</title>
    <style>
        .color {
            background-color: #04af2f;
            color: white;
        }
        .font {
            font-size: 40px;
        }
        .align {
            text-align: center;
        }
    </style>
</head>
<body>
    <p>Hii..</p>
    <p id="add" class="color font align">
        Welcome to Tutorials Point...
    </p>
    <button onclick="fun()">Click me</button>
    <p id="token"></p>
    <script>

        function fun() {
            let x = document.getElementById("add").classList.values();
            let result = "";
            for (let i of x) {
                result += i + "<br>";
            }
            document.getElementById("token").innerHTML = result;
        }
    </script>
</body>
</html>

Supported Browsers

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