Node.parentElement
read-only property returns the DOM node's parent
元素
,或
null
if the node either has no parent, or its parent isn't a DOM
元素
.
parentElement = node.parentElement
parentElement
is the parent element of the current node. This is always a DOM
元素
object, or
null
.
if (node.parentElement) {
node.parentElement.style.color = "red";
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of '
parentElement
' in that specification.
|
实时标准 | 初始定义。 |
On some browsers, the
parentElement
property is only defined on nodes that are themselves an
元素
. In particular, it is not defined on text nodes.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
parentElement
|
Chrome 1 | Edge 12 | Firefox 9 |
IE
9
注意事项
|
Opera 7 | Safari 1.1 | WebView Android 1 | Chrome Android 18 | Firefox Android 9 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
见实现注意事项。
节点
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