このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Element: firstElementChild プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

Element.firstElementChild は読み取り専用のプロパティで、要素の最初の子を Element で返します。子要素がない場合は null を返します。

Element.firstElementChild は要素ノードのみを含みます。 テキストやコメントノードなど、要素以外のノードを含むすべての子ノードを取得するには、 Node.firstChild を使用してください。

Element オブジェクト、または null です。

html
<ul id="list"> <li>First (1)</li> <li>Second (2)</li> <li>Third (3)</li> </ul> <script> const list = document.getElementById("list"); console.log(list.firstElementChild.textContent); // logs "First (1)" </script> 

仕様書

Specification
DOM
# ref-for-dom-parentnode-firstelementchild①

ブラウザーの互換性

関連情報