Proprietà XML DOM nodeType
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e ottiene il tipo di nodo dal primo elemento <title>:
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;
}
L'output del codice sopra sarà:
1
Definizione e utilizzo
La proprietà nodeType restituisce il tipo di nodo del nodo selezionato.
Sintassi
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 |
Dimostrazioni fai-da-te
❮ Oggetto Elemento