# 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

- the `firstElementChild` property
  that contains the first element
- the `lastChild` property
  that contains the last node
- the `childNodes` property
  that contains all element nodes

← →
↑
en ru