Returns a reference to the last child of the current element.
The childNodes collection contains the direct descendants of an element, in source order. The firstChild property retrieves the first item from the childNodes collection. Similarly, the lastChild property returns the last item from the childNodes collection. The childNodes collection also contains the text and comment nodes, not only HTML elements. If you only need those HTML elements that are direct descendants of an element, use the children collection.
You can find the related objects in the Supported by objects section below.
This property is read-only.
Reference to the last child.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the lastChild property and childNodes collection:
Did you find this example helpful?
User Contributed Comments