Skip to content
Related Articles

Related Articles

HTML DOM TreeWalker lastChild() method
  • Last Updated : 07 Jul, 2020
GeeksforGeeks - Summer Carnival Banner

The TreeWalker lastChild() method moves the current Node to the last visible child of the current node, and returns the last found child. If no such child exists in the document, this method returns null.


node = treeWalker.lastChild();

Parameters: This method takes no parameters.

Return Value:

  • Returns lastChild of the node if exists.
  • Returns null if no such child exists.

Example: In this example, create a TreeWalker with head node and hence showed the lastchild of that TreeWalker node.

<!doctype html>
    <meta charset="utf-8">
<title>HTML DOM TreeWalker lastChild() method</title>    
    <p>Click Below</p>
    <button onclick="get()">Click</button>
        var treeWalker = document.createTreeWalker(
        { acceptNode: function(node) {
 return NodeFilter.FILTER_ACCEPT; } },
        function get(){
            var node = treeWalker.lastChild();


Before Button Click:

After Button Click: In console, the last child of the TreeWalker node that is <title> can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up
Recommended Articles
Page :