The HTML DOM appendChild() Method of the node interface, is used to create a text node as the last child of the node. This method is also used to move an element from one element to another element. It is used for creating a new element with some text then first create the text as the text node and then append it to the element, then append the element to the document.
Syntax:
node.appendChild(node);
Parameters: This method accepts a single parameter node which is mandatory and used to specify the node object which needs to be appended.
The insertBefore() method in HTML DOM is used to insert a new node before the existing node as specified by the user.
Syntax:
node.insertBefore( newnode, existingnode )
Parameters: This method accepts two parameters as mentioned above and described below:
- newnode: It is the required parameter. This parameter contains the new node object which need to insert.
- existingnode: It is the required parameter. It describes the position where new node insert before this node. If it set to null then insertBefore method will insert the new node at the end.