/
index.md
81 lines (62 loc) · 2.54 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
title: "Node: lookupNamespaceURI() メソッド"
slug: Web/API/Node/lookupNamespaceURI
l10n:
sourceCommit: 312081aabba3885b35a81107b3c2fc53428896c5
---
{{APIRef("DOM")}}
**`lookupNamespaceURI()`** は {{domxref("Node")}} インターフェイスのメソッドで、引数として接頭辞を受け取り、このノードに関連付けられた名前空間が見つかれば、その URI を返します(見つからなければ `null` を返します)。
## 構文
```js-nolint
lookupNamespaceURI(prefix)
```
### 引数
- `prefix`
- : 検索する接頭辞です。
> **メモ:** この引数は省略可能ではありませんが、 `null` に設定することはできます。
### 返値
指定された接頭辞に対応する名前空間 URI の入った文字列です。
接頭辞が見つからない場合、 `null` を返します。
要求された `prefix` が `null` である場合は、既定の名前空間 URI を返します。
## 例
```html
Namespace URL for <code>xlink</code> on <output>:
<output>未検査</output>.<br />
Namespace URL for <code>xml</code> on <output>:
<output>未検査</output>.<br />
Namespace URL for <code>html</code> on <output>:
<output>未検査</output>.<br />
Namespace URL for <code>``</code> on <output>:
<output>未検査</output>.<br />
Namespace URL for <code>svg</code> on <svg>:
<output>未検査</output>.<br />
Namespace URL for <code>xlink</code> on <svg>:
<output>未検査</output>.<br />
Namespace URL for <code>xml</code> on <svg>:
<output>未検査</output>.<br />
<svg xmlns:svg="http://www.w3.org/2000/svg" height="1"></svg>
<button>ここをクリックして結果を確認</button>
```
```js
const button = document.querySelector("button");
button.addEventListener("click", () => {
const aHtmlElt = document.querySelector("output");
const aSvgElt = document.querySelector("svg");
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");
});
```
{{ EmbedLiveSample('Example','100%',190) }}
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{domxref("Node.lookupPrefix")}}
- {{domxref("Node.isDefaultNameSpace")}}