文档: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①

浏览器兼容性

另见