XML DOM nodeType Property
❮ Element Object
Example
The following code fragment loads "books.xml" into xmlDoc and gets the node type from the first <title> element:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    
var x = xmlDoc.getElementsByTagName("title")[0];
    
document.getElementById("demo").innerHTML = 
    x.nodeType;
}
The output of the code above will be:
1
Try it Yourself »
Definition and Usage
The nodeType property returns node type of the selected node.
Syntax
elementNode.nodeType
| Node Number: | Node Name: | 
|---|---|
| 1 | Element | 
| 2 | Attribute | 
| 3 | Text | 
| 4 | CDATA Section | 
| 5 | Entity Reference | 
| 6 | Entity | 
| 7 | Processing Instruction | 
| 8 | Comment | 
| 9 | Document | 
| 10 | Document Type | 
| 11 | Document Fragment | 
| 12 | Notation | 
Try-It-Yourself Demos
nodeType - Skip empty text nodes
❮ Element Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.