Open In App

HTML DOM ownerDocument Property

Improve
Improve
Like Article
Like
Save
Share
Report

The ownerDocument property returns the top-level document object of the node. Here, the owner document of the node is returned as the document object. It is a read-only property.

Syntax:

node.ownerDocument;

Properties:

  1. nodeName property: It returns the name of the specified node. If the node is an element node, it will return the tag name else if the node is an attribute node, it will return the attribute name else for different node types, different names will be returned.

    syntax:

    node.ownerDocument.nodeName;

    Return Value: The owner document of the node, is returned as the document object.

    Example 1 : Showing nodeName property




    <!DOCTYPE html>
    <html>
      
    <body>
      
        <h1><center>Geeks <button onclick="node()">
          Press
          </button>
          </center>
      </h1>
      
        <h4>DOM ownerDocument Property</h4>
        <p>It returns the owner document of the node 
          as document object. Click 'Press' to see the
          node name of this <p1> element.</p>
      
        <p1 id="PP"></p1>
        <p1 id="p2"></p1>
        <p1 id="pl"></p1>
      
        <script>
            function node() {
      
                var x = document.getElementById(
                 "PP").ownerDocument.nodeName;
                document.getElementById("p2").innerHTML = 
                  "Node name of the owner document "+
                  "of this <p1> element  is";
      
                document.getElementById("pl").innerHTML = x
      
            }
        </script>
      
    </body>
      
    </html>

    
    

    Output:

    • Before clicking on the button:
    • After clicking on the button:
  2. nodeType property: It returns the node type, as a number, of the specified node.
    Eg: 1 is returned for an element node and
    2 is returned for attribute node.

    syntax:

    node.ownerDocument.nodeType;

    Return Value: The owner document of the node, is returned as the document object.

    Example-2: Showing nodeType property




    <!DOCTYPE html>
    <html>
      
    <body>
      
        <h1><center>Geeks <button onclick="node()">
          Press
          </button>
          </center
      </h1>
      
        <h4>DOM ownerDocument Property</h4>
        <p>It returns the owner document of the node
          as document object. Click 'Press' to see 
          the node type of this <p1> element.
      </p>
      
        <p1 id="PP"></p1>
        <p1 id="p2"></p1>
        <p1 id="pl"></p1>
      
        <script>
            function node() {
      
                var x = document.getElementById(
                  "PP").ownerDocument.nodeType;
                
                document.getElementById("p2").innerHTML = 
                  "Node name of the owner document "+
                  "of this <p1> element  is";
      
                document.getElementById("pl").innerHTML = x
      
            }
        </script>
      
    </body>
      
    </html>

    
    

    Output:

    • Before clicking on the button:
    • After clicking on the button:

Browser Support: The browsers supported by DOM ownerDocument property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 9 and above
  • Opera 12.1 and above
  • Safari 1 and above


Last Updated : 13 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads