XML DOM tagName attribute

Definition and usage

The tagName property returns the tag name of the selected element.

Syntax:

elementNode.tagName

Example

In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().

The following code snippet retrieves the tag name of the first <title> element in "books.xml":

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.tagName);

The output of the above code is:

title