Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Element.firstElementChild

概述

ParentNode.firstElement 是一个只读属性,返回当前元素的第一个子元素节点,如果没有子元素节点,则返回null

语法

var childNode = elementNodeReference.firstElementChild; 

例子

<p id="para-01">
  <span>First span</span>
</p>

<script type="text/javascript">
  var p01 = document.getElementById('para-01');
  alert(p01.firstElementChild.nodeName)
</script>

弹出框显示 "SPAN".

规范

Specification Status Comment
DOM
ParentNode.firstElementChild
Living Standard Splitted the ElementTraversalinterface in ChildNode and ParentNode. This method is now defined on the latter.
The Document and DocumentFragment implemented the new interfaces.
Element Traversal Specification
ElementTraversal.firstElementChild
Recommendation Added its initial definition to theElementTraversal pure interface and use it on Element.

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (on Element) 1.0 3.5 (1.9.1) 9.0 10.0 4.0
Support on Document and DocumentFragment 29.0 25.0 (25.0) 未实现 16.0 未实现
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (on Element) (Yes) 1.0 (1.9.1) (Yes) (Yes) (Yes)
Support on Document and DocumentFragment (Yes) 25.0 (25.0) 未实现 16.0 未实现

相关链接

文档标签和贡献者

 此页面的贡献者: teoli, AlexChao, ziyunfei
 最后编辑者: AlexChao,