offline version v3


156 of 264 menu

firstChild property

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

Syntax

element.firstChild;

Example

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

<div id="parent">text<p>paragraph</p><!-- comment --></div> let parent = document.querySelector('#parent'); let text = parent.firstChild.textContent; console.log(text);

The code execution result:

'text'

See also

enru