Open In App

HTML DOM nodeType Property

The DOM nodeType Property is used to find out the type of the node that we are referring to. The type for a particular node is returned in numerical form. DOM nodeType property is a read-only property. 

Return value : It returns a numeric value as according to the type of node.



Syntax:

 nodeName.nodeType

Example-1: 






<!DOCTYPE html>
<html>
  
<head>
    <title>
      HTML|DOM nodeType Property
    </title>
    <style>
        p,
        h5 {
            color: green;
        }
    </style>
</head>
  
<body style="text-align: center;">
    <p id="gfg">
      GeeksforGeeks
    </p>
    <h5>
      Welcome to GeeksforGeeks
    </h5>
  
    <button onclick="node()">
        Click here to know the node type.
    </button>
  
    <p id="nodetype"></p>
  
    <script>
        function node() {
            var geek = document.getElementById("gfg").nodeType;
  
            // innerHTML fetches value of element 
            // valued "nodetype" 
            // and update it with new value of variable
            // "geek"(nodeType value of geek)
            document.getElementById("nodetype").innerHTML = geek;
        }
    </script>
</body>
  
</html>

Output: 

Before:

  

After:

  

Example-2: 




<!DOCTYPE html>
<html>
  
<head>
    <title>HTML|DOM nodeType Property</title>
    <style>
        h5 {
            color: green;
        }
    </style>
</head>
  
<body style="text-align: center;">
    <h3>Welcome to GeeksforGeeks</h3>
  
    <button onclick="nType()">
        Click here to know the node type.
    </button>
  
    <p id="nodetype"></p>
  
    <script>
        // nType() function is used to fetch our node
        // and find out its type 
        function nType() {
            var geek = document.body.nodeType;
            document.getElementById("nodetype").innerHTML = geek;
        }
    </script>
</body>
  
</html>

Output: 

Before:

  

After:

  

Supported Browsers:


Article Tags :