The firstChild property

The firstChild property stores the element's first child node. If the element has no children, then null is returned.

Syntax

javascriptelement.firstChild;

Example

Let's get a text of the first element node:

html<div id="parent">text<p>parag</p><!--com--></div>
javascriptlet parent = document.querySelector('#parent');
let text = parent.firstChild.textContent;

console.log(text);

The code execution result:

javascript'text'

See also