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.