Latest web development tutorials

XML DOM localName property

Element Object Reference Element object

Definition and Usage

localName property returns the local name (element name) selected element.

If the node is not an element or attribute is selected, this property returns NULL.

grammar

elementNode.localName

Example 1

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and made a local name from the first <book> element:

Examples

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 fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and made a local name from the last child node:

Examples

//check if the last node is an element 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 Reference Element object