XML DOM lookupPrefix() Method

Node Object Reference Manual

Definition and Usage

The lookupPrefix() method can return the prefix that matches the specified namespace on the node.

Syntax:

nodeObject.lookupPrefix(URI)
Parameter Description
URI Required. Namespace URI.

Example

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

The following code snippet can find the prefix of the namespace URI of the first <book> element:

xmlDoc=loadXMLDoc("books_ns.xml");
var x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.lookupPrefix("http://www.codew3c.com/children/"));

Output:

c

Node Object Reference Manual