TreeWalker.parentNode()
method moves the current
节点
to the first
visible
ancestor node in the document order, and returns the found node. If no such node exists, or if it is above the
TreeWalker
's
root
node
,返回
null
and the current node is not changed.
node = treeWalker.parentNode();
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
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
parentNode
|
Chrome 1 | Edge 12 | Firefox 4 | IE 9 | Opera 9 | Safari 3 | WebView Android 3 | Chrome Android Yes | Firefox Android 4 | Opera Android 10.1 | Safari iOS 3 | Samsung Internet Android Yes |
完整支持
TreeWalker
interface it belongs to.
TreeWalker
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TypeInfo
USVString
UserDataHandler
XMLDocument