aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/domtokenlist/contains/index.html
blob: 5baaea76dfd2cd7b81b6443f8bf7483e2fb5da88 (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
---
title: DOMTokenList.contains()
slug: Web/API/DOMTokenList/contains
translation_of: Web/API/DOMTokenList/contains
---
<p>{{APIRef("DOM")}}</p>

<p>The <code><strong>contains()</strong></code> method of the {{domxref("DOMTokenList")}} interface returns a {{domxref("Boolean")}}<code>true</code> if the underlying list contains the given <em>token</em>, otherwise <code>false</code>.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">tokenList.contains(token);</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt>token</dt>
 <dd>A {{domxref("DOMString")}} representing the token you want to check for the existance of in the list.</dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p>A {{domxref("Boolean")}}<code>true</code> if the underlying list contains the given <em>token</em>, otherwise <code>false</code>.</p>

<h2 id="Examples">Examples</h2>

<p>In the following example we retrieve the list of classes set on a {{htmlelement("span")}} element as a <code>DOMTokenList</code> using {{domxref("Element.classList")}}. We then test for the existance of "c" in the list, and write the result into the <code>&lt;span&gt;</code>'s {{domxref("Node.textContent")}}.</p>

<p>First, the HTML:</p>

<pre class="brush: html">&lt;span class="a b c"&gt;&lt;/span&gt;</pre>

<p>Now the JavaScript:</p>

<pre class="brush: js">var span = document.querySelector("span");
var classes = span.classList;
var result = classes.contains("c");
if(result) {
  span.textContent = "The classList contains 'c'";
} else {
   span.textContent = "The classList does not contain 'c'";
}</pre>

<p>The output looks like this:</p>

<p>{{ EmbedLiveSample('Examples', '100%', 60) }}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG','#dom-domtokenlist-contains','contains()')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.DOMTokenList.contains")}}</p>