blob: 5a5113de0496f0141ab19f0cee81b8cb942b68b8 (
plain)
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
|
---
title: DOMTokenList.remove()
slug: Web/API/DOMTokenList/remove
tags:
- API
- DOM
- DOMTokenList
- Method
- Reference
- remove
- メソッド
translation_of: Web/API/DOMTokenList/remove
---
<p>{{APIRef("DOM")}}</p>
<p>{{domxref("DOMTokenList")}} インターフェイスの <code><strong>remove()</strong></code> メソッドは、リストから指定された<em>トークン</em>を削除します。</p>
<h2 id="Syntax">構文</h2>
<pre
class="brush: js"><var>tokenList</var>.remove(<var>token1</var>[, <var>token2</var>[, ...<var>tokenN</var>]]);</pre>
<h3 id="Parameters">引数</h3>
<dl>
<dt><code><var>token<em>N</em></var></code></dt>
<dd>リストから削除したいトークンを表す {{domxref("DOMString")}} です。リストに文字列がない場合、エラーはスローされず、何も起こりません。</dd>
</dl>
<h3 id="Return_value">返値</h3>
<p>なし。</p>
<h2 id="Examples">例</h2>
<p>以下の例では、 {{htmlelement("span")}} 要素に設定されたクラスのリストを、 {{domxref("Element.classList")}} を使って <code>DOMTokenList</code> として受け取ります。それからリストからトークンを削除し、 <code><span></code> の {{domxref("Node.textContent")}} の中にリストを書き込みます。</p>
<p>最初に HTML です。</p>
<pre class="brush: html"><div id="ab" class="a b c"></div>
<div id="a" class="a b c"></div></pre>
<p>そして JavaScript です。</p>
<pre class="brush: js">let span = document.getElementById("ab");
let classes = span.classList;
classes.remove("c");
span.textContent = classes;
</pre>
<p>複数のクラスを一度に削除するために、複数のトークンを渡すことができます。渡す順序は、リスト中に出現する順序と一致している必要はありません。</p>
<pre class="brush: js">let span2 = document.getElementById("a")
let classes2 = span2.classList;
classes2.remove("c", "b");
span2.textContent = classes2;
</pre>
<p>出力結果は以下のようになります。</p>
<p>{{ EmbedLiveSample('Examples', '100%', 60) }}</p>
<h2 id="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
<th scope="col">状態</th>
<th scope="col">備考</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('DOM WHATWG','#dom-domtokenlist-remove','remove()')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td>初回定義</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("api.DOMTokenList.remove")}}</p>
|