XML DOM localName Property
Element Object
Definition and Usage
The localName property returns the local name (element name) of the selected element.
If the selected node is not an element or attribute, this property returns NULL.
Syntax
elementNode.localName
Example 1
The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, and from the first
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.localName);
The code above will output:
book
Try it »
Example 2
The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, and get the local name from the last child node:
Example
//
Get the last child node
function
get_lastchild
(
n
)
{
x
=
n
.
lastChild
;
while
(
x
.
nodeType
!=
1
)
{
x
=
x
.
previousSibling
;
}
return
x
;
}
xmlDoc
=
loadXMLDoc
(
"
books.xml
"
)
;
x
=
xmlDoc
.
documentElement
;
lastNode
=
get_lastchild
(
x
)
;
document
.
write
(
lastNode
.
localName
)
;
The code above will output:
book
Try it »
Element Object