Node.parentNode
read-only property returns the parent of the specified node in the DOM tree.
parentNode = node.parentNode
parentNode
is the parent of the current node. The parent of an element is an
元素
node, a
Document
node, or a
DocumentFragment
节点。
if (node.parentNode) {
// remove a node from the tree, unless
// it's not in the tree already
node.parentNode.removeChild(node);
}
Document
and
DocumentFragment
nodes
can never have a parent, so
parentNode
will always return
null
.
It also returns
null
if the node has just been created and is not yet attached to the tree.
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'Node: parentNode' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
parentNode
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 7 | Safari 1.1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
Node.firstChild
Node.lastChild
Node.childNodes
Node.nextSibling
Node.parentElement
Node.previousSibling
Node.removeChild
节点
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
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument