HTML DOM appendChild() Method Last Updated : 11 Sep, 2024 Comments Improve Suggest changes Like Article Like Report The HTML DOM appendChild() method adds a new child node to the end of a specified parent node's child list. It can move existing nodes or add new nodes, allowing dynamic updates to the document structure by appending elements, text, or other nodes.Syntax:node.appendChild(node);Parameters: This method accepts a single parameter node which is mandatory and used to specify the node object that needs to be appended.Example 1: This example describes the use of the appendChild() method that will create the text node as the last child of the node. HTML <!DOCTYPE html> <html> <head> <title> HTML DOM appendChild() Method </title> <style> h1, h2 { font-weight: bold; color: green; } body { margin-left: 130px; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM appendChild() Method</h2> <ul id="gfg"> <li>Computer Network</li> <li>Data Structures using C</li> </ul> <button onclick="geeks()"> Submit </button> <script> function geeks() { let node = document.createElement("LI"); let textnode = document.createTextNode("Web Technology"); node.appendChild(textnode); document.getElementById("gfg").appendChild(node); } </script> </body> </html> Output:DOM appendChild() MethodExample 2: This example describes the use of the appendChild() method by appending the text to the document after clicking the submit button. HTML <!DOCTYPE html> <html> <head> <title> HTML DOM appendChild() Method </title> <style> #sudo { border: 1px solid green; background-color: green; margin-bottom: 10px; color: white; font-weight: bold; } h1, h2 { text-align: center; color: green; font-weight: bold; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM appendChild() Method</h2> <div id="sudo"> The Good Website is learning for Computer Science is- </div> <button onclick="geeks()"> Submit </button> <script> function geeks() { let node = document.createElement("P"); let t = document.createTextNode("GeeksforGeeks"); node.appendChild(t); document.getElementById("sudo").appendChild(node); } </script> </body> </html> Output:DOM appendChild() MethodUsed Methods with appendChild()document.createElement(): Creates a new HTML element specified by the tag name. If the element name is not recognized, an unknown HTML element is created.document.createTextNode(): Creates a text node containing a string. This method is used to add text to an element.document.getElementById(): Retrieves an element by its ID, allowing for targeted appending of nodes.We have a complete list of HTML DOM methods, to check those please go through this HTML DOM Object Complete reference article.Supported Browsers: The browser supported by DOM appendChild() Method are listed below:Google ChromeEdge FirefoxOperaSafariWe have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript. Comment More infoAdvertise with us Next Article HTML DOM appendChild() Method M manaschhabra2 Follow Improve Article Tags : Misc Web Technologies HTML HTML-DOM Practice Tags : Misc Similar Reads HTML DOM anchors Collection The HTML DOM anchors collection is used to return the collection of all <a> elements. It only counts those <a> element that has the name attribute only. The name attribute of the anchor element does not support HTML 5. The elements in the collection are sorted that appear in the source c 2 min read HTML DOM close() Method The DOM close() method is used to close the output stream. It is used to indicate the finish of writing on a window. The close() method does not require any parameter. Syntax:document.close()Example 1: In this example, we will use DOM close() method.HTML<!DOCTYPE html> <html> <head 2 min read HTML DOM baseURI Property The DOM baseURI property is used to return the base Uniform Resource Identifier (URI) of the document. This property is used for read-only. This property returns a string value that represents the base URI of the page.Syntax: node.baseURIReturn Value: It returns a string value that represents the UR 2 min read HTML DOM body Property The HTML DOM Body property is used to set the document <body> element. It only returns the content present in the <body> Tag. This property is used to change the present content inside the <body> element and sets them with the new specified content. This property does not return th 2 min read HTML DOM createAttribute() Method This createAttribute() method is used to create an attribute with the specified name and returns the attribute object. The attribute.value property is used to set the value of the attribute and the element.setAttribute() method is used to create a new attribute for an element. This method() contains 2 min read HTML DOM doctype Property The DOM doctype property is used to return the doctype of any HTML document. The DocumentType object is the name property used to return the name of the object. If there is no doctype declared in the document then it returns a Null value. Syntax:document.doctypeExample: In this example, we will use 2 min read HTML DOM writeln() Method The writeln() method is used to write a document with the additional property of a newline character after each statement. This method is similar to the document.write() method. Syntax: document.writeln( exp1, exp2, exp3, ... )Parameters: This method contains many parameters which are optional. All 1 min read HTML DOM console error() Method The console.error() method in HTML is used to display an error message on the console. The console.error() method is used for testing purposes. The error message is sent as a parameter to the console.error() method. Syntax:console.error( message )Parameters: This method accepts a single parameter me 2 min read HTML DOM console groupCollapsed() Method The console.groupCollapsed() method in HTML is used to create a collapsed group of messages in the console. It indicates the start of a collapsed message group and all the messages written after calling the console.groupCollapsed() method will write inside the message group. The label is sent as an 2 min read HTML DOM console count() Method The console.count() method in HTML is used to write the number of times the console.count() method is called. The console.count() method can be added to a label that will be included in the console view. The label is an optional parameter sent to the console.count() method. Syntax:console.count( lab 2 min read Like