DOM的一些Tips
parentNode && parentElement
parentNode与parentElement在功能上是一样的,都是返回当前节点的父节点
parentNode is the parent of the current node. The parent of an element is an Element node, a Document node, or a DocumentFragment node. The Node.parentElement read-only property returns the DOM node's parent Element, or null if the node either has no parent, or its parent isn't a DOM Element.
其中parentNode兼容性更好,符合W3C标准 DOM Level 2 Core: Node.parentNode DOM Level 3 Core: Node.parentNode 相比之下,parentElement只是在部分浏览器中可以使用,比如IE 所以应该使用parentNode
ownerDocument && elementDocument
ownerDocument返回某一元素的根节点文档对象(document对象) elementDocument返回文档根节点
The Node.ownerDocument read-only property returns the top-level document object for this node. The Document.documentElement read-only property returns the Element that is the root element of the document (for example, the element for HTML documents).
document = element.ownerDocument
element = document.documentElement;