Open In App
Related Articles

HTML DOM createTextNode() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The createTextNode() method is used to create a TextNode which contains an element node and a text node. It is used to provide text to an element. This method contains the text values as parameter which is of string type.

Syntax: 

document.createTextNode( text )

Parameters: This method accepts single parameter text which is mandatory. It is used to specify the text of the text node.

Example: In this example, we will use createTextNode() method

HTML

<!DOCTYPE html>
<html>
   
<head>
    <title>DOM createTextNode() Method</title>
    <style>
        h1,
        h2 {
            color: green;
            font-weight: bold;
        }
    </style>
</head>
 
<body>
    <h1>GeeksForGeels</h1>
    <h2>DOM createTextNode() Method</h2>
    <button onclick="geeks()">
      Submit
      </button>
    <script>
        function geeks() {
            let x =
                document.createTextNode("GeeksForGeeks");
            document.body.appendChild(x);
        }
    </script>
</body>
   
</html>

                    

Output: 

Supported Browsers: The browser supported by DOM createTextNode() Method  are listed below: 

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 7
  • Safari 1


Last Updated : 03 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads