append() method is used to append or join the text to the given element.
Example - Appending text to the given element
- In the next step using append() method we are adding some text to the given element (elem.append("New Content");).
- Then we are getting the parent div element (document.getElementById("idDiv1");) and storing in elem2 variable.
- Finally using the alert method, we are displaying the whole parent content, including the text we added (alert(elem2.outerHTML);).