JavaScript: Node Name

By Xah Lee. Date: .
Return the node's (tag) name (a string), if the node is a element node (nodeType is 1). If it's a text node, the value is "#text".

[see HTML/CSS Case Sensitivity]

You can use str.toLowerCase() to convert it.

// first paragraph
document.getElementsByTagName("p")[0].nodeName // "P"

// first paragraph's content
document.getElementsByTagName("p")[0].childNodes[0].nodeName // "#text"

As of , this works in all major browsers.

JavaScript/DOM: Node Name, Node Type, Node Value

JavaScript in Depth

DOM Scripting


DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc