This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



Gets a reference to the first child node in the childNodes collection of the object.

If the node is childless, null is returned.

Property of dom/Nodedom/Node


var result = element.firstChild;
element.firstChild = value;

Return Value

Returns an object of type ElementElement


The following code example implements the firstChild attribute to get the first child element of an object.

<ul id ="oList">
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
<script type="text/javascript">
var oFirstChild = oList.firstChild;

The following example shows how the firstChild method will include white space nodes #text.

<p id="para-01">
  First span
<p id="p2">first span, no whitespace</p>
<script type="text/javascript">
  var p01 = document.getElementById('para-01');
  alert(p01.firstChild.nodeName);// #text
  var p2=document.getElementById('p2');
  alert(p2.firstChild.nodeName);// SPAN


Standards information