lastChild (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No Yes
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Full Full Full Full


var child = node.lastChild;

In the example above, if node has any immediate child nodes (of any type), the child variable will be a reference to the last one; otherwise it will be null.

In the following HTML example, the lastChild of the p element is a strong element, and the lastChild of the strong element is a text node with the value premium acid techno:

  <dfn>TB-303 Bassline</dfn> is a legendary analog synth,
  producing a unique sound that is the trademark signature of
  <strong>premium acid techno</strong>
Note: This example doesn’t take account of whitespace

Actually this example is idealized, and in some browsers the strong element may not in fact be the lastChild of the p element; that's because some browsers count intermediate whitespace as text nodes, and would therefore consider the lastChild to be the whitespace between the </strong> and </p> tags.

For more about this behavior please see DOM Core.


The last node that is a direct child of this node (ie. this node is its parent and it appears at the end of the childNodes collection), or null if there is no such node.

This property is readonly.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Full Full Full Full Full Full Full Full Full Full Full

No known issues.

User-contributed notes

There are no comments yet.

Related Products