Web APIs

Element.firstElementChild

Try the free JavaScript compiler

Return the first direct element child, ignoring text and comment nodes. Example console output: STRONG.

Formal Syntax & Structure

javascript syntaxjavascript
element.firstElementChild

Return Value

Element or null

First child element or null.

Working Example

Example Snippetjavascript
const root=document.createElement("div"); root.append("heading",document.createElement("strong")); console.log(root.firstElementChild.tagName);
JavaScript Reference