Categories
JavaScript Answers

How to set DOM element as first child with JavaScript?

Spread the love

To set DOM element as first child with JavaScript, we call the prepend method.

For instance, we write

parent.prepend(newChild);

to call prepend with newChild to put newChild before all other child nodes in parent.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *