Skip to content
Related Articles

Related Articles

HTML | DOM createTextNode() Method
  • Difficulty Level : Basic
  • Last Updated : 19 Apr, 2021

The createTextNode() method is used to create a TextNode which contains 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 text node.
Example: 
 

html




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

Output: 

Before Clicking on Button:



After Clicking on Button:
 

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

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

 

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :