TreeWalker: parentNode() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheTreeWalker.parentNode() method moves the currentNode to the firstvisible ancestor node in the document order,and returns the found node. If no such node exists, or if it is above theTreeWalker'sroot node, it returnsnull and the currentnode is not changed.
In this article
Syntax
js
parentNode()Parameters
None.
Return value
ANode object ornull.
Examples
js
const treeWalker = document.createTreeWalker( document.body, NodeFilter.SHOW_ELEMENT, { acceptNode(node) { return NodeFilter.FILTER_ACCEPT; }, }, false,);const node = treeWalker.parentNode(); // returns null as there is no parentSpecifications
| Specification |
|---|
| DOM> # dom-treewalker-parentnode> |
Browser compatibility
See also
- The
TreeWalkerinterface it belongs to.