XML DOM ownerDocument attribute

Definition and usage

The ownerDocument attribute returns the document object of the selected element.

Syntax:

elementNode.ownerDocument

Instance

In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().

The following code snippet retrieves the name and nodetype of the owner document of the first <title> element in "books.xml":

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0];
x=x.ownerDocument;
document.write("Nodename: " + x.nodeName);
document.write(" (nodetype: " + x.nodeType + ")");

The output of the above code:

Nodename: #document (nodetype: 9)