English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
tagNameL'attributo readonly restituisce il nome del tag dell'elemento sul quale è stato chiamato.
Nel HTML, il valore restituito dall'attributo del nome del tag è sempre in maiuscolo.
Puoi anche usarenodeNameL'attributo restituisce il nome del tag dell'elemento. La differenza rispetto a nodeName è che quest'ultimo restituisce anche i nodi attributo, i nodi testo e i nodi commento.
element.tagName
var x = document.getElementById("myPara").tagName;Prova a vedere‹/›
L'attributo tagName è supportato da tutti i browser:
Proprietà | |||||
tagName | Sì | Sì | Sì | Sì | Sì |
Valore di ritorno: | Una stringa String che rappresenta il nome del tag dell'elemento in maiuscolo |
---|---|
Versione DOM: | Livello DOM 1 |
Restituisce i nomi dei tag degli elementi figli dell'elemento BODY:
var x = document.body.children; var txt = ""; for (let i = 0; i < x.length; i++) { txt += x[i].tagName + "<br>"; } document.getElementById("para").innerHTML = txt;Prova a vedere‹/›
Usa insieme all'attributo event.target il nome del tag per trovare quali elementi hanno scatenato l'evento specificato:
var x = event.target.tagName;Prova a vedere‹/›
Riferimento HTML DOM:Proprietà nodeName di node