The lastChild
property returns the last child node of the specified node as a Node object.
lastChild |
Yes | Yes | Yes | Yes | Yes |
var v = node.lastChild
The last child of the node as a Node object.
The following code shows how to get the last child node in a list.
<!DOCTYPE html>
<html>
<body>
<p>text</p>
<ul id="myList"><li>A</li><li>B</li></ul>
<!-- w w w. java 2 s . c o m-->
<p id="demo">this is a test</p>
<button onclick="myFunction()">test</button>
<script>
function myFunction()
{
var l=document.getElementById("myList");
var x=document.getElementById("demo");
x.innerHTML=l.lastChild.nodeName;
}
</script>
</body>
</html>
The code above is rendered as follows: