Categories
JavaScript Answers

How to get the immediate first child element with JavaScript?

Spread the love

Sometimes, we want to get the immediate first child element with JavaScript.

In this article, we’ll look at how to get the immediate first child element with JavaScript.

How to get the immediate first child element with JavaScript?

To get the immediate first child element with JavaScript, we use the firstChild property.

For instance, we write

console.log(parentElement.firstChild);

to get the first child of the parentElement with parentElement.firstChild.

Conclusion

To get the immediate first child element with JavaScript, we use the firstChild property.

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 *