lastChild property

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

Syntax

javascriptelement.lastChild;

Example

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

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

console.log(text);

The code execution result:

javascript'com'

See also