Open In App

HTML DOMTokenList add() Method

Last Updated : 12 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The TokenList add() Method in HTML DOM is used to add one or more tokens or nodes in a DOM TokenList Object.   

Syntax:

domtokenlist.add(token)

Parameter Values: It contains a value i.e token which specifies the name of the token that will be added to a TokenLIst. It is a required parameter.  

 Return Value: It does not return any value. 

Example: Below HTML code illustrate the use of add() method.

HTML




<!DOCTYPE html>
<html>
<head>
    <style>
        .gfg {
            background-color: green;
            font-size: 50px;
        }
    </style>
</head>
 
<body>
    <h2 id="gfg">
        GeeksforGeeks
    </h2>
    <h2>
        HTML DOM TokenList add() Method
    </h2>
    <button onclick="myGeek()">Submit</button>
 
    <script>
        function myGeek() {
            var elem = document.getElementById("gfg");
 
            // Adding class to div element
            elem.classList.add("gfg");
        }
    </script>
</body>
</html>


Output:

 

Supported Browsers:

  • Google Chrome 8 and above
  • Edge 12 and above
  • Internet Explorer 10 and above
  • Opera Mini 12.1 and above
  • Firefox 3.6 and above
  • Apple Safari 5.1 and above

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads