CKTIS / JavaScript
Element.lastElementChild — the last element child
Element.lastElementChild returns the last direct child that is an element, or null. It skips text and comments.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
element.lastElementChildElement.lastElementChild is a read-only property supplied by the ParentNode mixin. Read it without parentheses: element.lastElementChild.
It returns the last direct Element child in tree order, or null if none exists. It does not search deeper descendants. Unlike lastChild, it skips text nodes, including whitespace, and comments.
Check for null before using the result. Reading again reflects tree changes. This is a DOM API, not a feature of a particular ECMAScript edition; a Node.js version alone does not establish availability.
Examples
const parent = document.createElement('div');
const child = document.createElement('span');
child.id = 'last';
parent.append(child, document.createTextNode(' '), document.createComment('end'));
console.log(parent.lastElementChild.id);
console.log(parent.lastChild.nodeType === 8);
child.remove();
console.log(parent.lastElementChild === null);Result
last true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.