HTML | DOM ownerDocument Property

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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>

    chevron_right

    
    

    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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>

    chevron_right

    
    

    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
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.