--- title: Node.ownerDocument slug: Web/API/Node/ownerDocument translation_of: Web/API/Node/ownerDocument ---
Node.ownerDocument
唯讀屬性會回傳一個此節點所屬的的頂層 document
物件。
document = element.ownerDocument
document
is the {{domxref("Document", "document")}} object parent of the current element.// given a node "p", get the top-level HTML child // of the document object var d = p.ownerDocument; var html = d.documentElement;
The document
object returned by this property is the main object with which all the child nodes in the actual HTML document are created. If this property is used on a node that is itself a document, the result is null
.
Specification | Status | Comment |
---|---|---|
{{SpecName("DOM4", "#dom-node-ownerdocument", "Node.ownerDocument")}} | {{Spec2("DOM4")}} | |
{{SpecName("DOM3 Core", "core.html#node-ownerDoc", "Node.ownerDocument")}} | {{Spec2("DOM3 Core")}} | No change |
{{SpecName("DOM2 Core", "core.html#node-ownerDoc", "Node.ownerDocument")}} | {{Spec2("DOM2 Core")}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}}[1] | 6.0[2] | {{CompatVersionUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatVersionUnknown}}[1] | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] Starting in Gecko 9.0 {{geckoRelease("9.0")}}, the ownerDocument
of doctype nodes (that is, nodes for which {{domxref("Node.nodeType")}} is Node.DOCUMENT_TYPE_NODE
or 10) is no longer null
. Instead, the ownerDocument
is the document on which document.implementation.createDocumentType()
was called.
[2] http://msdn.microsoft.com/en-us/library/ie/ms534315(v=vs.85).aspx