Get the node type of the owner document of a <p> element:
var x = document.getElementById("myP").ownerDocument.nodeType;
<!DOCTYPE html> <html> <body> <p id="myP">Click the button get the node type of the owner document of this &lt;p&gt; element.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//www . j av a 2s .c o m var x= document.getElementById("myP").ownerDocument.nodeType; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The ownerDocument property returns the owner document of a node, as a Document object.
In HTML, the HTML document itself is the ownerDocument of an element.