The lookupNamespaceURI()
method of the Node
interface takes a prefix as parameter and returns the namespace URI associated with it on the given node if found (and null
if not).
Node.lookupNamespaceURI()
Syntax
lookupNamespaceURI(prefix);
Parameters
-
prefix
-
The prefix to look for.
Note: This parameter is not optional, but can be set to
null
.
Return value
A string containing the namespace URI corresponding to the prefix. If the prefix is not found, it returns null
. If the requested prefix
is null
, it returns the default namespace URI.
Example
Namespace URL for <code>xlink</code> on <output>: <output>Not tested</output>.<br/> Namespace URL for <code>xml</code> on <output>: <output>Not tested</output>.<br/> Namespace URL for <code>html</code> on <output>: <output>Not tested</output>.<br/> Namespace URL for <code>``</code> on <output>: <output>Not tested</output>.<br/> Namespace URL for <code>svg</code> on <svg>: <output>Not tested</output>.<br/> Namespace URL for <code>xlink</code> on <svg>: <output>Not tested</output>.<br/> Namespace URL for <code>xml</code> on <svg>: <output>Not tested</output>.<br/> <svg xmlns:svg="http://www.w3.org/2000/svg" height="1"></svg> <button>Click to see the results</button>
const button = document.getElementsByTagName('button')[0]; button.addEventListener("click", function () { const aHtmlElt = document.getElementsByTagName('output')[0]; const aSvgElt = document.getElementsByTagName('svg')[0]; const result = document.getElementsByTagName('output'); result[0].value = aHtmlElt.lookupNamespaceURI("xlink"); result[1].value = aHtmlElt.lookupNamespaceURI("xml"); result[2].value = aHtmlElt.lookupNamespaceURI("html"); result[3].value = aHtmlElt.lookupNamespaceURI(""); result[4].value = aSvgElt.lookupNamespaceURI("svg"); result[5].value = aSvgElt.lookupNamespaceURI("xlink"); result[6].value = aSvgElt.lookupNamespaceURI("xml"); });
Specifications
Specification |
---|
DOM Standard # dom-node-lookupnamespaceuri |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
lookupNamespaceURI |
1
|
12
|
1
|
9
|
≤12.1
|
3
|
1
|
18
|
4
|
≤12.1
|
1
|
1.0
|
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Node/lookupNamespaceURI