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. Listing 6-8 demonstrates using them.

Listing 6-8: Using appendChild(), and insertBefore() methods

Get hands-on with 1200+ tech skills courses.