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.
ParentNode.append( ChildNodesToPrepend );
Parameters: This parameter holds the set of Node or DOMString objects that is to be inserted as the last child of parent element.
Below examples illustrate the ParentNode.append() method:
Example 1: In this example, we will append an element. To show this method, we have created three elements parentNode, Child1 and Child2. Then we have appended the Child1 and Child2 to parentNode.
In console, we had shown childNodes of parentNode.
In console, you can see childNodeList of parentNode. One is p and one is div.
Example 2: In this example, we have appended some text to innerHTML of the element and the element’s textContent.
In console, you can see textContent of parent element.
- Google Chrome
- Apple Safari