Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM localName Property

XML DOM localName Property


Element Object Reference 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 get the local name of an element:

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 Reference Element Object