In an HTML document, the document.createElement() is a method used to create the HTML element. The element specified using elementName is created or an unknown HTML element is created if the specified elementName is not recognized.
Syntax:
let element = document.createElement(“elementName”);
In the above syntax, elementName is passed as a parameter. elementName specifies the type of the created element. The nodeName of the created element is initialized to the elementName value. The document.createElement() returns the newly created element.
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.