XML DOM localNameProperty


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 usesloadXMLDoc()put "books.xml" Load into xmlDoc, and get the local name from the first <book> element:

Example

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book")[0];

document.write(x.localName);

The above code will output:

book

Try it Yourself »

Example 2

The following code snippet usesloadXMLDoc()put "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 above code will output:

book

Try it Yourself »

Element objectother extensions