Example 1: This example using the approach discussed above. Approach 1: Select an element whose child element is going to be selected. The index starts at 0. RSS Feed. Definition and Usage. The firstChild and lastChild return the first and last child of a node, which can be any node type including text node, comment node, and element node. Let us say you have the following HTML code: The following example selects all child nodes of the