HTML DOM createElement() Method Last Updated : 02 Sep, 2024 Comments Improve Suggest changes Like Article Like Report 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. Syntaxlet 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. Example 1: This example illustrates how to create a <p> element. Input : HTML <!DOCTYPE html> <html> <head> <script> function createparagraph() { let x = document.createElement("p"); let t = document.createTextNode("Paragraph is created."); x.appendChild(t); document.body.appendChild(x); } </script> </head> <body> <button onclick="createparagraph()">CreateParagraph</button> </body> </html> Output: Explanation:Start with creating an <p> element using document.createElement().Create a text node using document.createTextNode().Now, append the text to <p> using appendChild().Append the <p> to <body> using appendChild().Example 2: This example illustrates how to create a <p> element and append it to a <div> element. Input : HTML <!DOCTYPE html> <html> <head> <script> function createparagraph() { let x = document.createElement("p"); let t = document.createTextNode("Paragraph is created."); x.appendChild(t); document.getElementById("divid").appendChild(x); } </script> </head> <body> <div id="divid"> A div element</div> <button onclick="createparagraph()">CreateParagraph</button> </body> </html> Output: Supported Browser: The browsers supported by DOM createElement() Method are listed below:Google ChromeEdge FirefoxOperaSafari Comment More infoAdvertise with us Next Article HTML DOM createElement() Method C chaitanyashah707 Follow Improve Article Tags : JavaScript Web technologies HTML-DOM HTML-Methods Similar Reads HTML DOM createEvent() Event Method The createEvent() method in HTML creates an event object of the specified type. The created event must be initialized before use. Syntax:document.createEvent(event_type)event_type: It is the required parameter and is used to specify the type of event. There are many types of events which are listed 2 min read HTML DOM getElementsByTagName() Method The getElementsByTagName() method in the HTML DOM allows the selection of elements by their tag name. It returns a collection of elements with the specified tag name within the specified document or element. To extract any info just iterate through all the elements using the length property. Syntax: 3 min read HTML DOM length Property The DOM length property in HTML is used to get the number of items in a NodeList object. A NodeList is a collection of child Nodes. For example, the NodeList of the body will contain all the child nodes in the body i.e. paragraphs, comments, headings, script, etc.Syntax: nodelist.lengthReturn Value: 2 min read HTML DOM value Property The DOM value property in HTML is used to set or return the value of any attribute.Syntax: It returns the attribute value. attribute.valueIt is used to set a value to the property. attribute.value = valueProperty Value: value: It defines the value of the attribute.Return Value: It returns a string v 2 min read HTML DOM normalize() Method The normalize() method in HTML is used to merge the adjacent text nodes with the first text node and flush out the empty nodes. The normalize() method does not require any parameter. Syntax: node.normalize() Example 1: In this example, we will use normalize() method. HTML <!DOCTYPE html> <h 2 min read HTML DOM links Collection The DOM links collection is used to return the collection of all <a> and <area> elements with the "href" attribute in the HTML document. The elements in the collection are sorted as they appear in the sourcecode. Syntax: document.links Properties: It contains a single property length whi 4 min read HTML DOM open() Method The DOM Open() method in HTML is the combination of the following three steps: Opens an output stream to collect the output.Collects output from the document.write() or document.writeln() methods.Runs the document.close to display the output written to the output stream. Syntax: document.open( MIMEt 2 min read HTML DOM designMode Property The DOM designMode property in HTML is used to specify whether the document is editable or not. It can also be used to set the document editable. Syntax:Set: This property is used to set whether the document is editable or not.document.designMode = "on|off";Get: This property is used to return wheth 2 min read HTML DOM Style borderCollapse Property The DOM Style borderCollapse property in HTML is used to set or return whether the border of the table collapsed into a single border or not. Syntax: It is used to return the borderCollapse property.object.style.borderCollapse It is used to set borderCollapse property.object.style.borderCollapse = " 2 min read HTML DOM Style borderBottom Property The DOM style borderBottom property is used to set or return the three different border-bottom properties such as border-bottom-width, border-bottom-style, and border-bottom-color of an element. Syntax: It returns the borderBottom Property.object.style.borderBottomIt is used to set the borderBottom 2 min read Like