aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/domtokenlist/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ko/web/api/domtokenlist/index.html')
-rw-r--r--files/ko/web/api/domtokenlist/index.html115
1 files changed, 115 insertions, 0 deletions
diff --git a/files/ko/web/api/domtokenlist/index.html b/files/ko/web/api/domtokenlist/index.html
new file mode 100644
index 0000000000..a3b7c6fd97
--- /dev/null
+++ b/files/ko/web/api/domtokenlist/index.html
@@ -0,0 +1,115 @@
+---
+title: DOMTokenList
+slug: Web/API/DOMTokenList
+tags:
+ - API
+ - DOM
+ - DOMTokenList
+ - Interface
+ - Reference
+translation_of: Web/API/DOMTokenList
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p>The <code><strong>DOMTokenList</strong></code> interface represents a set of space-separated tokens. Such a set is returned by {{domxref("Element.classList")}}, {{domxref("HTMLLinkElement.relList")}}, {{domxref("HTMLAnchorElement.relList")}}, {{domxref("HTMLAreaElement.relList")}}, {{domxref("HTMLIframeElement.sandbox")}}, or {{domxref("HTMLOutputElement.htmlFor")}}. It is indexed beginning with <code>0</code> as with JavaScript {{jsxref("Array")}} objects. <code>DOMTokenList</code> is always case-sensitive.</p>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt>{{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}</dt>
+ <dd>Is an <code>integer</code> representing the number of objects stored in the object.</dd>
+ <dt>{{domxref("DOMTokenList.value")}}</dt>
+ <dd>The value of the list as a {{domxref("DOMString")}}.</dd>
+</dl>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{domxref("DOMTokenList.item()")}}</dt>
+ <dd>Returns an item in the list by its index (returns <code>undefined</code> if the number is greater than or equal to the length of the list).</dd>
+ <dt>{{domxref("DOMTokenList.contains()")}}</dt>
+ <dd>Returns <code>true</code> if the list contains the given <em>token</em>, otherwise <code>false</code>.</dd>
+ <dt>{{domxref("DOMTokenList.add()")}}</dt>
+ <dd>Adds the given <em>token</em> to the list.</dd>
+ <dt>{{domxref("DOMTokenList.remove()")}}</dt>
+ <dd>Removes the specified <em>token</em> from the list.</dd>
+ <dt>{{domxref("DOMTokenList.replace()")}}</dt>
+ <dd>Replaces an existing <em>token</em> with a new token.</dd>
+ <dt>{{domxref("DOMTokenList.supports()")}}</dt>
+ <dd>Returns <code>true</code> if a given <em>token</em> is in the associated attribute's supported tokens.</dd>
+ <dt>{{domxref("DOMTokenList.toggle()")}}</dt>
+ <dd>Removes a given <em>token</em> from the list and returns <code>false</code>. If <em>token</em> doesn't exist it's added and the function returns <code>true</code>.</dd>
+ <dt>{{domxref("DOMTokenList.entries()")}}</dt>
+ <dd>Returns an {{jsxref("Iteration_protocols","iterator")}} allowing you to go through all key/value pairs contained in this object.</dd>
+ <dt>{{domxref("DOMTokenList.forEach()")}}</dt>
+ <dd>Executes a provided function once per <code>DOMTokenList</code> element.</dd>
+ <dt>{{domxref("DOMTokenList.keys()")}}</dt>
+ <dd>Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing you to go through all keys of the key/value pairs contained in this object.</dd>
+ <dt>{{domxref("DOMTokenList.values()")}}</dt>
+ <dd>Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing you to go through all values of the key/value pairs contained in this object.</dd>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<p>In the following simple example we retrieve the list of classes set on a {{htmlelement("p")}} element as a <code>DOMTokenList</code> using {{domxref("Element.classList")}}, add a class using {{domxref("DOMTokenList.add()")}}, and then update the {{domxref("Node.textContent")}} of the <code>&lt;p&gt;</code> to equal the <code>DOMTokenList</code>.</p>
+
+<p>First, the HTML:</p>
+
+<pre class="brush: html">&lt;p class="a b c"&gt;&lt;/p&gt;</pre>
+
+<p>Now the JavaScript:</p>
+
+<pre class="brush: js">var para = document.querySelector("p");
+var classes = para.classList;
+para.classList.add("d");
+para.textContent = 'paragraph classList is "' + classes + '"';</pre>
+
+<p>The output looks like this:</p>
+
+<p>{{ EmbedLiveSample('Examples', '100%', 60) }}</p>
+
+<h2 id="Trimming_of_whitespace_and_removal_of_duplicates">Trimming of whitespace and removal of duplicates</h2>
+
+<p>Methods that modify the <code>DOMTokenList</code> (such as {{domxref("DOMTokenList.add()")}}) automatically trim any excess {{Glossary("Whitespace")}} and remove duplicate values from the list. For example:</p>
+
+<pre class="brush: html">&lt;span class=" d d e f"&gt;&lt;/span&gt;</pre>
+
+<pre class="brush: js">var span = document.querySelector("span");
+var classes = span.classList;
+span.classList.add("x");
+span.textContent = 'span classList is "' + classes + '"';</pre>
+
+<p>The output looks like this:</p>
+
+<p>{{ EmbedLiveSample('Trimming_of_whitespace_and_removal_of_duplicates', '100%', 60) }}</p>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("DOM WHATWG", "#interface-domtokenlist", "DOMTokenList")}}</td>
+ <td>{{Spec2("DOM WHATWG")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.DOMTokenList")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("DOMSettableTokenList")}} (object that extends <code>DOMTokenList</code> with settable <em>.value</em> property)</li>
+</ul>