lastChild (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM1 | No | No | Yes |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
Example
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:
<p> <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> </p>
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.
Description
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.
Compatibility
| 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.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.