Element.firstElementChild

Table of contents

  1. 1. Summary
  2. 2. Syntax and values
  3. 3. Example
  4. 4. See also
Table of contents
  1. 1. Summary
  2. 2. Syntax and values
  3. 3. Example
  4. 4. See also

Introduced in Gecko 1.9.1

(Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

« Gecko DOM Reference

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.

Tags (3)

Edit tags

Attachments (0)

 

Attach file