Node lastChild Property - Javascript DOM

Javascript examples for DOM:Node


The lastChild property returns the last child node of the specified node, as a Node object.

lastChild returns the last child node as an element node, a text node or a comment node.

lastElementChild returns the last child node as an element node ignoring text and comment nodes.

Whitespace inside elements is considered as text, and text is considered as nodes.

This property is read-only.

Return Value

A Node object, representing the last child of a node, or null if there are no child nodes

The following code shows how to get the HTML content of the last child node of an <ul> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<select id="mySelect" size="4">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {//from   w  w w .  j a va  2 s  . c  om
    var x = document.getElementById("mySelect").lastChild.text;
    document.getElementById("demo").innerHTML = x;


Related Tutorials