This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

parentNode

Summary

Retrieves the parent object in the document hierarchy relative to the current node and updates currentNode.

Method of dom/TreeWalkerdom/TreeWalker

Syntax

var node = treewalker.parentNode();

Return Value

Returns an object of type DOM NodeDOM Node

Object that receives the parent node in the filtered TreeWalker hierarchy.

Examples

var treewalker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_ELEMENT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
var node = treewalker.parentNode(); // returns null as there is no parent

Notes

Remarks

parentNode sets the currentNode to the returned node.

If no such node exists, or if it is above the TreeWalker's root node, returns null and the current node is not changed.

Syntax

Standards information

Related specifications

DOM
Living Standard

Attributions