HTML DOM ParentNode.prepend() Method Last Updated : 11 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The HTML DOM ParentNode.prepend() method inserts nodes or strings at the beginning of a parent element's child nodes. It can add multiple nodes or text directly as its arguments. Unlike appendChild(), which adds to the end, prepend() places content at the start.Syntax:ParentNode.prepend( ChildNodesToPrepend );Parameters: ChildNodesToPrepend: Child nodes to prepend act as Parameters for this method.prepend text: We can prepend text also.Return Value: This method returns undefined.The below examples illustrate the ParentNode.prepend() method:Example 1: Prepending an element. To show this method, we have created three elements parentNode, Child1 and Child2. Then we prepended Child1 and Child2 to parentNode.In the console, we had shown childNodes of parentNode. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Prepend</title> </head> <body> <h1>GeeksforGeeks</h1> <script> let parentNode = document.createElement("div"); let Child1 = document.createElement("p"); let Child2 = document.createElement("div"); parentNode.prepend(Child1); parentNode.prepend(Child2); console.log(parentNode.childNodes); </script> </body> </html> Output: In the console, you can see the childNodeList of parentNode.One is div and one is p Example 2:Prepending text. In this example, we have prepended some text to the innerHTML of the element and the element's textContent. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Prepend</title> </head> <body> <h1>GeeksforGeeks</h1> <script> let parent = document.createElement("div"); parent.innerHTML = "A Computer Science Portal for Geeks"; parent.prepend("GeeksforGeeks : "); console.log(parent.textContent); </script> </body> </html> Output: In the console, you can see the textContent of the parent element. Comment More infoAdvertise with us Next Article HTML DOM removeChild() Method T taran910 Follow Improve Article Tags : JavaScript HTML-DOM Similar Reads HTML DOM TreeWalker parentNode() method The TreeWalker parentNode() method moves the current Node to the first visible ancestor node or parent node of TreeWalker in the document order, and returns the found node. If no such child exists in the document, this method returns null. Syntax: node = treeWalker.parentNode(); Parameters: This met 1 min read HTML DOM ParentNode.append() Method The ParentNode.append() method is used to insert Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as Text nodes. Syntax: ParentNode.append( ChildNodesToPrepend ); Parameters: This parameter holds the set of Node or DOMString objects that is to 2 min read HTML DOM parentNode Property The parentNode property is used to return the parent node of the specified node as a Node object. It is a read-only property. Syntax: node.parentNode Return value: This property returns a parent element of the specified node or null if the current node has no parent element. Example: In this example 2 min read HTML DOM setAttributeNode() Method The setAttributeNode() method in HTML DOM is used to add the specified attribute node to an element. If the specified attribute is already present, then this method replaces it. Syntax: element.setAttributeNode(name) Parameter: Only one parameter is accepted name.Where the name is the attribute node 1 min read HTML DOM removeChild() Method The HTML DOM removeChild() method is used to remove a specified child node of the given element. It returns the removed node as a node object or null if the node doesn't exist. Syntax: node.removeChild(child) Parameters: This method accepts a single parameter child which is mandatory. It represents 2 min read HTML DOM replaceChild() Method The replaceChild() method in HTML DOM is used to replace a child node with a new node within the given parent node. Syntax: parentNode.replaceChild( newChild, oldChild ) Parameter Values: This method accepts two parameters which are listed below: newChild: It is the required parameter. It represents 1 min read Like