-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
86 lines (66 loc) · 3.14 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
82
83
84
85
86
---
title: "Node: lookupPrefix() メソッド"
slug: Web/API/Node/lookupPrefix
l10n:
sourceCommit: 312081aabba3885b35a81107b3c2fc53428896c5
---
{{APIRef("DOM")}}
**`lookupPrefix()`** は {{domxref("Node")}} インターフェイスのメソッドで、指定された名前空間 URI に対応する接頭辞があれば、それを含む文字列を返します。ない場合は `null` を返します。
複数の接頭辞の可能性があれば、最初の接頭辞を返します。
## 構文
```js-nolint
lookupPrefix(namespace)
```
### 引数
- `namespace`
- : 接頭辞を検索するための名前空間の入った文字列です。
> **メモ:** この引数は省略可能ではありませんが、 `null` に設定することはできます。
### 返値
対応する接頭辞の入った文字列です。見つからなかった場合は `null` になります。
`namespace` が null または空文字列であった場合、 `lookupPrefix()` は `null` を返します。
このノードが {{domxref("DocumentType")}} または {{domxref("DocumentFragment")}} であった場合は、 `lookupPrefix()` は常に `null` を返します。
## 例
```html
Prefix for <code>http://www.w3.org/2000/svg</code> on <output>:
<output>未検査</output><br />
Prefix for <code>http://www.w3.org/XML/1998/namespace</code> on <output>:
<output>未検査</output><br />
Prefix for <code>http://www.w3.org/TR/html4/</code> on <output>:
<output>未検査</output><br />
Prefix for <code>https://www.w3.org/1999/xlink</code> on <output>:
<output>未検査</output><br />
Prefix for <code>http://www.w3.org/2000/svg</code> on <svg>:
<output>未検査</output><br />
Prefix for <code>https://www.w3.org/1999/xlink</code> on <svg>:
<output>未検査</output><br />
Prefix for <code>http://www.w3.org/XML/1998/namespace</code> on <svg>:
<output>未検査</output><br />
<svg xmlns:t="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.lookupPrefix("http://www.w3.org/2000/svg"); // true
result[1].value = aHtmlElt.lookupPrefix(
"http://www.w3.org/XML/1998/namespace",
); // false
result[2].value = aHtmlElt.lookupPrefix("http://www.w3.org/TR/html4/"); // true
result[3].value = aHtmlElt.lookupPrefix("https://www.w3.org/1999/xlink"); // false
result[4].value = aSvgElt.lookupPrefix("http://www.w3.org/2000/svg"); // true
result[5].value = aSvgElt.lookupPrefix("https://www.w3.org/1999/xlink"); // true
result[6].value = aSvgElt.lookupPrefix(
"http://www.w3.org/XML/1998/namespace",
); // false
});
```
{{ EmbedLiveSample('Example','100%',190) }}
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [http://www.w3.org/TR/DOM-Level-3-Cor...amespacePrefix](https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespacePrefix)