nodeName
Summary
Gets the name of a particular type of node.
Syntax
Note: This property is read-only.
var nodeName = node.nodeName;
Return Value
Returns an object of type StringString
The uppercase name of the node if Content type is text/html, else the lowercase name of the node if Content type is xhtml or any other xml content type.
Examples
The following code example uses the nodeName property to obtain the name of an element.
<body>
<ul id="oList">
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
<script type="text/javascript">
// returns the element name 'LI' of the list item labeled 'List Item 2'
var sName = document.getElementById("oList").childNodes(1).nodeName;
</script>
</body>
Notes
The html spec allows tag names of either case, upper or lower-case. The xhtml spec requires tag names in lower-case only. For interoperability between html and xhtml, and for markup re-use in html and xhtml documents user lower-case tag names in your source markup.
Using lower-case tag names in your source markup also require less keystrokes!
Read more details on nodeName case sensitivity in different browsers.
Related specifications
- DOM Level 3 Core
- Recommendation
Attributions
Mozilla Developer Network : [Node.nodeName Article]
Microsoft Developer Network: [nodeName Property Article]