Esempio
Ottenere il nome del nodo di un <p> elemento:
var x = document.getElementById("myP").nodeName;
Il risultato di x sarà:
P
Prova tu stesso " Più "Try it Yourself" esempi di seguito.
Definizione e l'utilizzo
La proprietà nodeName restituisce il nome del nodo specificato.
Se il nodo è un nodo elemento, la proprietà nodeName restituirà il nome del tag.
Se il nodo è un nodo di attributi, la proprietà nodeName restituirà il nome dell'attributo.
Per gli altri tipi di nodo, la proprietà nodeName tornerà nomi diversi per i diversi tipi di nodi.
Suggerimento: è anche possibile utilizzare la tagName proprietà per restituire il nome del tag di un elemento. La differenza è che tagName restituire solo i nomi dei tag, mentre nodeName restituisce il nome di tutti i nodi (tags, attributes, text, comments) .
Questa proprietà è di sola lettura.
Supporto browser
Proprietà | |||||
---|---|---|---|---|---|
nodeName | sì | sì | sì | sì | sì |
Sintassi
node .nodeName
Dettagli tecnici
Valore di ritorno: | Una stringa, che rappresenta il nome del nodo. Valori possibili:
|
---|---|
DOM Version | Nucleo Livello 1 Nodo Oggetto |

Altri esempi
Esempio
Ottenere il nome del nodo del <body> elemento:
var x = document.body.nodeName;
Il risultato di x sarà:
BODY
Prova tu stesso " Esempio
I nomi dei nodi dei <body> nodi figlio dell'elemento:
var c = document.body.childNodes;
var txt = "";
var i;
for (i =
0; i < c.length; i++) {
txt = txt + c[i].nodeName +
"<br>";
}
document.getElementById("demo").innerHTML = txt;
Il risultato di txt sarà:
#text
P
#text
BUTTON
#text
P
#text
#comment
#text
DIV
#text
P
#text
SCRIPT
#text
Prova tu stesso " Esempio
Ottenere il nome del nodo, valore del nodo e il tipo di nodo del <div> primo nodo figlio dell'elemento:
<div id="myDIV">This is a div element.</div>
<script>
var x = document.getElementById("myDIV").firstChild;
var txt = "";
txt += "The node name: " + x.nodeName + "<br>";
txt += "The node value: "
+ x.nodeValue + "<br>";
txt += "The node type: " + x.nodeType;
</script>
Il risultato di txt sarà:
The node name: #text
The node value: This is a div element.
The node
type: 3
Prova tu stesso " Pagine correlate
Di riferimento HTML DOM: elemento. tagName Proprietà
Di riferimento HTML DOM: nodo. nodeType Proprietà
Di riferimento HTML DOM: nodo. nodeValue Proprietà
Di riferimento HTML DOM: nodo. childNodes Proprietà