Prop Element Nodename
## XML DOM nodeName Property
The `nodeName` property is a standard property of the XML DOM (Document Object Model) used to retrieve the name of a specified node. When applied to an Element node, it returns the tag name of that element.
---
## Definition and Usage
The `nodeName` property returns the name of the selected node as a string.
Depending on the node type, the value returned by `nodeName` varies:
* For **Element** nodes, it returns the tag name (e.g., `"title"`, `"book"`).
* For **Attribute** nodes, it returns the attribute name.
* For **Text** nodes, it always returns `"#text"`.
* For **Document** nodes, it always returns `"#document"`.
*Note: In XML DOM, the returned tag name preserves the original casing defined in the XML document. In HTML DOM, the returned tag name is always in uppercase.*
---
## Syntax
```javascript
elementNode.nodeName
```
### Return Value
* **Type:** String
* **Description:** The name of the node (the tag name for element nodes).
---
## Code Example
The following example demonstrates how to load an XML document (`books.xml`) using a helper function `loadXMLDoc()` and retrieve the node name of the first `` element.
### Sample XML File (`books.xml`)
```xml
Everyday Italian
Giada De Laurentiis
2005
30.00
```
### JavaScript Implementation
```javascript
// Load the XML document
var xmlDoc = loadXMLDoc("books.xml");
// Get the first element in the document
var x = xmlDoc.getElementsByTagName("title");
// Output the node name of the element
document.write("Node Name: " + x.nodeName);
```
### Output
```text
title
```
---
## Key Considerations
1. **Read-Only Property:** The `nodeName` property is read-only. You cannot modify the name of an existing node using this property.
2. **Case Sensitivity:** In XML, tag names are case-sensitive. The `nodeName` property will return the exact casing used in the source XML file.
3. **Difference from `localName`:** While `nodeName` returns the fully qualified name (including any namespace prefix, e.g., `prefix:localName`), the `localName` property returns only the local part of the node name, ignoring the namespace prefix.
YouTip