问题描述
有人可以用尽可能简单的说明来解释我,古典DOM ,最近在Firefox 9中引入 parentElement
Firefox 9和DOM4,但它已经存在于所有其他主流浏览器中。
在大多数情况下,它与 parentNode
。唯一的区别是当节点的 parentNode
不是元素时。如果是这样, parentElement
是 null
。
示例:
document.body.parentNode; //< html>元素
document.body.parentElement; //< html>元素
document.documentElement.parentNode; //文档节点
document.documentElement.parentElement; // null
由于< html>
元素( document.documentElement
)没有父元素是一个元素, parentElement
是空
。 (还有其他更不可能的情况,其中 parentElement
可以是 null
,但是你可能永远不会遇到他们。)
Can somebody in explain me in as simple as possible terms, what is the difference between classical DOM parentNode and newly introduced in Firefox 9 parentElement
parentElement
is new to Firefox 9 and to DOM4, but it has been present in all other major browsers for ages.
In most cases, it is the same as parentNode
. The only difference comes when a node's parentNode
is not an element. If so, parentElement
is null
.
As an example:
document.body.parentNode; // the <html> element
document.body.parentElement; // the <html> element
document.documentElement.parentNode; // the document node
document.documentElement.parentElement; // null
Since the <html>
element (document.documentElement
) doesn't have a parent that is an element, parentElement
is null
. (There are other, more unlikely, cases where parentElement
could be null
, but you'll probably never come across them.)
这篇关于DOM parentNode和parentElement之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!