offline version v3


158 of 264 menu

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

enru