HTML - DOMTokenList length Property



HTML DOMTokenList length property is a read-only property and used to get the number of tokens in a token list.

Syntax

domtokenlist.length;

Return Value

It returns a number representing number of tokens in token list.

Example of HTML DOMTokenList 'length' Property

<!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>Number of tokens in DOMTokenList :</p>
    <p id="token"></p>
    <script>
        function fun() {
            let x = document.getElementById("add").classList.length;
            document.getElementById("token").innerHTML = x;
        }
    </script>
</body>

</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
length Yes 8 Yes 12 Yes 3.6 Yes 5.1 Yes 12.1
html_dom.htm
Advertisements