Element.lastElementChild

Table of contents

  1. 1. Summary
  2. 2. Syntax and values
  3. 3. Example
  4. 4. See also
  5. 5. Specification

Introduced in Gecko 1.9.1

(Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

« Gecko DOM Reference

Summary

lastElementChild returns the element's last child element or null if there are no child elements.

Syntax and values

var childNode = elementNodeReference.lastElementChild; 

childNode is a reference to the last 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>
  <b>bold</b>
</p>

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

In this example, the alert shows "B", which is the name of the last child node of the paragraph element.

Specification

lastElementChild was introduced in the W3C Element Traversal Specification.

Tags (3)

Edit tags

Attachments (0)

 

Attach file