Adding New Child Elements to the Document

In this lesson, we will add new child elements to our document tree. Let's begin!

After you have grabbed a document element, you can add child elements to it with the appendChild() and insertBefore() methods.

The first method appends a new child to the end of the list of exiting children

The second method allows specifying the position of insertion. The Listing below demonstrates using them.

Listing: Using appendChild(), and insertBefore() methods

Get hands-on with 1400+ tech skills courses.