This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The lookupPrefix() method of the Node interface returns a string containing the prefix for a given namespace URI, if present, and null if not. When multiple prefixes are possible, the first prefix is returned.
lookupPrefix(namespace)
namespaceA string containing the namespace to look the prefix up.
Note: This parameter is not optional but can be set to null.
A string containing the corresponding prefix, or null if none has been found. If namespace is null, or the empty string, lookupPrefix() returns null.
If the node is a DocumentType or a DocumentFragment, lookupPrefix() always returns null.
Prefix for <code>http://www.w3.org/2000/svg</code> on <output>: <output>Not tested</output>.<br /> Prefix for <code>http://www.w3.org/XML/1998/namespace</code> on <output>: <output>Not tested</output>.<br /> Prefix for <code>http://www.w3.org/TR/html4/</code> on <output>: <output>Not tested</output>.<br /> Prefix for <code>https://www.w3.org/1999/xlink</code> on <output>: <output>Not tested</output>.<br /> Prefix for <code>http://www.w3.org/2000/svg</code> on <svg>: <output>Not tested</output>.<br /> Prefix for <code>https://www.w3.org/1999/xlink</code> on <svg>: <output>Not tested</output>.<br /> Prefix for <code>http://www.w3.org/XML/1998/namespace</code> on <svg>: <output>Not tested</output>.<br /> <svg xmlns:t="http://www.w3.org/2000/svg" height="1"></svg> <button>Click to see the results</button>
const button = document.querySelector("button");
button.addEventListener("click", () => {
const htmlElt = document.querySelector("output");
const svgElt = document.querySelector("svg");
const result = document.getElementsByTagName("output");
result[0].value = htmlElt.lookupPrefix("http://www.w3.org/2000/svg"); // true
result[1].value = htmlElt.lookupPrefix(
"http://www.w3.org/XML/1998/namespace",
); // false
result[2].value = htmlElt.lookupPrefix("http://www.w3.org/TR/html4/"); // true
result[3].value = htmlElt.lookupPrefix("https://www.w3.org/1999/xlink"); // false
result[4].value = svgElt.lookupPrefix("http://www.w3.org/2000/svg"); // true
result[5].value = svgElt.lookupPrefix("https://www.w3.org/1999/xlink"); // true
result[6].value = svgElt.lookupPrefix("http://www.w3.org/XML/1998/namespace"); // false
});
| Specification |
|---|
| DOM> # dom-node-lookupprefix> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
lookupPrefix |
1 | 12 | 1 | ≤12.1 | 3 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Node/lookupPrefix