Table of contents
- 1. Summary
- 2. Syntax and values
- 3. Example
- 4. See also
Summary
firstElementChild returns the element's first child element or null if there are no child elements.
Syntax and values
var childNode = elementNodeReference.firstElementChild;
childNode is a reference to the first child element of the element node, or null if there isn't one..
This attribute is read-only.
Example
<p id="para-01">
<span>First span</span>
</p>
<script type="text/javascript">
var p01 = document.getElementById('para-01');
alert(p01.firstElementChild.nodeName)
</script>
In this example, the alert shows "SPAN", which is the name of the first child node of the paragraph element.
Mozilla Developer Network