English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
L'attributo nodeName è una proprietà sola lettura che restituisce il nome del nodo corrente come stringa.
Se il nodo è un nodo elemento, l'attributo nodeName restituirà il nome del tag in maiuscolo.
Se il nodo è un nodo attributo, l'attributo nodeName restituirà il nome dell'attributo.
Per altri tipi di nodi, l'attributo nodeName restituirà diversi nomi per diversi tipi di nodi.
Attenzione:Puoi anche usaretagNameL'attributo restituisce il nome del tag dell'elemento. La differenza sta nel fatto che tagName restituisce solo il nome del tag, mentre nodeName restituisce il nome di tutti i nodi (tag, attributo, testo, commento).
node.nodeName
var x = document.getElementById("myPara").nodeName;Prova a vedere‹/›
Tutti i browser supportano completamente l'attributo nodeName:
Attributo | |||||
nodeName | È | È | È | È | È |
Valore restituito: | Stringa che rappresenta il nome del nodo. Valori possibili:
|
---|---|
Versione DOM: | Livello DOM 1 |
Restituisce il nome del nodo dei figli del elemento BODY:
var x = document.body.childNodes; var txt = ""; for (let i = 0; i < x.length; i++) { txt += x[i].nodeName + "<br>"; {} document.getElementById("para").innerHTML = txt;Prova a vedere‹/›
Restituisce il nome del nodo, il tipo del nodo e il valore del primo figlio del div:
<div id="div-1">Questo è un elemento div.</div> <script> var x = document.getElementById("div-1").firstChild; var txt = ""; txt += "Nome del nodo: " + x.nodeName + "<br>"; txt += "Valore del nodo: " + x.nodeValue + "<br>"; txt += "Tipo di nodo: " + x.nodeType; document.getElementById("para").innerHTML = txt; </script>Prova a vedere‹/›
Riferimento HTML DOM:node Proprietà .childNodes
Riferimento HTML DOM:node Proprietà .firstChild
Riferimento HTML DOM:node Proprietà .lastChild
Riferimento HTML DOM:node Proprietà .parentNode
Riferimento HTML DOM:node Proprietà .previousSibling
Riferimento HTML DOM:node Proprietà .nextSibling