Element: lastElementChild プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

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

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.lastElementChild.textContent);
  // logs "Third (3)"
</script>

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
lastElementChild

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報