XML DOM lookupPrefix() method

Definition and usage

The lookupPrefix() method returns the prefix that matches the specified namespace URI at the current node.

Syntax:

elementNode.lookupPrefix(URI)
Parameter Description
URI Required. The namespace prefix to be found.

Example

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

The following code snippet finds the prefix matching the namespace URI in the first <book> element:

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

The output of the above code is:

c