The nodeName read-only property returns the name of the current Node as a string.


var str = node.nodeName;


A DOMString. Values for the different types of nodes are:

Interface nodeName value
Attr The value of
CDATASection "#cdata-section"
Comment "#comment"
Document "#document"
DocumentFragment "#document-fragment"
DocumentType The value of
Element The value of Element.tagName
Entity The entity name
EntityReference The name of entity reference
Notation The notation name
ProcessingInstruction The value of
Text "#text"


Given the following markup:

<div id="d1">hello world</div>
<input type="text" id="t">

and the following script:

var div1 = document.getElementById("d1");
var text_field = document.getElementById("t");

text_field.value = div1.nodeName;

In XHTML (or any other XML format), text_field's value would read "div". However, in HTML, text_field's value would read "DIV", because nodeName and tagName return in upper case on HTML elements in DOMs flagged as HTML documents. Read more details on nodeName case sensitivity in different browsers.

Note that the Element.tagName property could have been used instead, since nodeName has the same value as tagName for an element. Bear in mind, however, that nodeName will return "#text" for text nodes while tagName will return undefined.


Specification Status Comment
The definition of 'nodeName' in that specification.
Living Standard

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
nodeNameChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes


Full support  
Full support
Compatibility unknown  
Compatibility unknown