Table of contents
- 1. Summary
- 2. Syntax and values
- 3. Example
- 4. See also
- 5. Specification
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.
See also
childElementCountchildrenfirstElementChildlastElementChildnextElementSiblingpreviousElementSibling
Specification
lastElementChild was introduced in the W3C Element Traversal Specification.
Mozilla Developer Network