# lastChild property

The `lastChild` property stores the last element node. If the element has no children, then `null` is returned.

## Syntax

`element.lastChild;`

## Example

Let's obtain a text of the last element node:

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

The code execution result:

`' comment '`

## See also

- the `lastElementChild` property
  that contains the last element
- the `firstChild` property
  that contains the first node
- the `childNodes` property
  that contains all element nodes

← →
↑
en ru