The TreeWalker previousSibling() method moves the current Node to its previous sibling if any and returns the found sibling. If no such child exists in the document, this method returns null.
node = treeWalker.previousSibling();
Parameters: This method takes no parameters.
- Returns previously visible sibling of the current 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 previously visible sibling of that TreeWalker’s last node.
Before Clicking the Button:
After Clicking the Button: In the console, the previous visible sibling of the body’s last element of the TreeWalker node that is <button> can be seen.
- Google Chrome
- Internet Explorer