Favorites

DOM Element.firstElementChild Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element.firstElementChild
DOM Element PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The firstElementChild property returns an element's first child element, skipping text nodes. lastElementChild returns the last.

Description

The read-only firstElementChild and lastElementChild properties return the element's first and last child elements, ignoring text and comment nodes, or null if it has no element children.

They're useful for working with simple structures, such as reading the first and last items of a list or the heading inside a card. If you need a child that matches a particular selector, querySelector(':scope > .item') is more robust than relying on position.

For moving between neighbouring elements, nextElementSibling and previousElementSibling are the matching sibling properties, and children gives the whole list.

Syntax

element.firstElementChild
element.lastElementChild

Value

The first (or last) child element, or null if there are none.

Example

<ul id="list">
  <li>First</li>
  <li>Middle</li>
  <li>Last</li>
</ul>
const list = document.getElementById('list');
console.log(list.firstElementChild.textContent);
console.log(list.lastElementChild.textContent);

Browser Support

The following information will show you the current browser support for the Element.firstElementChild property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee