DOM Element.firstElementChild Property
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.lastElementChildValue
The first (or last) child element, or null if there are none.
Example
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.
Desktop





Tablets & Mobile





