JS DOM: Node Name
node.nodeName-
- Return the node's (tag) name (a string), if the node is a element node (
nodeTypeis 1). - If it's a text node, the value is
"#text".
- For HTML document, the return value is usually all UPPER CASE. (regardless what's in the file.)
- For XML/XHTML, it is always lowercase (because XML allow just lowercase.) However, there are edge cases, when a DOM element is imported from htm/html5/xml, or when older browser encounters a tag it doesn't know.
γsee HTML: 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" - Return the node's (tag) name (a string), if the node is a element node (