XML DOM prefix property

Definition and usage

The prefix property returns the namespace prefix of the selected node.

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

Syntax:

elementNode.prefix

instance

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

The following code snippet retrieves the namespace prefix of the first <title> element in "books_ns.xml":

xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.prefix);

The output of the above code is:

c