文件:firstElementChild 屬性

Baseline 已廣泛支援

此功能已成熟,可跨多種裝置和瀏覽器版本工作。它自 ⁨2018 年 4 月⁩ 起已在所有瀏覽器中可用。

Document.firstElementChild 只讀屬性返回文件的第一個子 Element,如果沒有子元素則返回 null

對於 HTML 文件,這通常是唯一的子元素,即根 <html> 元素。

有關文件內特定元素的第一個子元素,請參閱 Element.firstElementChild

一個 Element 物件,或者 null

示例

js
document.firstElementChild;
// returns the root <html> element, the only child of the document

規範

規範
DOM
# ref-for-dom-parentnode-firstelementchild①

瀏覽器相容性

另見