Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. TreeWalker
  4. parentNode()

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.

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 parent

Specifications

Specification
DOM
# dom-treewalker-parentnode

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp