Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM TreeWalker previousNode() Method

  • Last Updated : 28 Jul, 2020

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


node = treeWalker.previousNode();

Parameters: This method takes no parameters.

Return Value:

  • Returns previous visible node if exists.
  • Returns null if no such child exists.

Example: In this example, a TreeWalker with body node is created and hence showed the previous visible node from the last child of body node of that TreeWalker node.


<!doctype html>
    <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.previousNode();


  • Before Clicking the Button:

  • After Clicking the Button: In the console, the previous visible child of the TreeWalker node that is <button> tag can be seen.

Supported Browsers: 

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!