Easy Tutorial
❮ Prop Element Baseuri Dom Prop Node Parentnode ❯

XML DOM localName Property



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


Example 1

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and retrieves the local name from the first <book> element:

Example

The above code will output:


Example 2

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and retrieves 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

❮ Prop Element Baseuri Dom Prop Node Parentnode ❯