HTML DOM nodeName Property

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








googletag.cmd.push(function() googletag.display('div-gpt-ad-1422003450156-2'); );




HTML DOM nodeName Property


Element Object




Example


Get the node name of a <p> element:



var x = document.getElementById("myP").nodeName;

<!--

The result of x will be:



P
-->
Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


The nodeName property returns the name of the specified node.


If the node is an element node, the nodeName property will return the tag name.


If the node is an attribute node, the nodeName property will return the name of the attribute.


For other node types, the nodeName property will return different names for different node types.


Tip: You can also use the tagName property to return the tag name of an element. The difference is that tagName only return tag names, while nodeName returns the name of all nodes (tags, attributes, text, comments).


This property is read-only.



Browser Support














Property
nodeName Yes Yes Yes Yes Yes

Syntax



node.nodeName







googletag.cmd.push(function() googletag.display('div-gpt-ad-1493883843099-0'); );





Technical Details






Return Value:
A String, representing the name of the node.

Possible values:


  • Returns the tagname for element nodes, in uppercase

  • Returns the name of the attribute for attribute nodes

  • Returns "#text" for text nodes

  • Returns "#comment" for comment nodes

  • Returns "#document" for document nodes

DOM Version Core Level 1 Node Object

More Examples



Example


Get the node name of the <body> element:



var x = document.body.nodeName;

<!--

The result of x will be:



BODY
-->
Try it Yourself »



Example


Get the node names of the <body> element's child nodes:



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;

<!--

The result of txt will be:



#text
P
#text
BUTTON
#text
P
#text
#comment
#text

DIV
#text
P
#text
SCRIPT
#text
-->
Try it Yourself »



Example


Get the node name, node value and the node type of the <div> element's first child node:



<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>

<!--

The result of txt will be:



The node name: #text
The node value: This is a div element.
The node type: 3
-->
Try it Yourself »


Related Pages


HTML DOM reference: element.tagName Property


HTML DOM reference: node.nodeType Property


HTML DOM reference: node.nodeValue Property


HTML DOM reference: node.childNodes Property



Element Object


Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)