Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 912173 of DOMTokenList

  • Revision slug: Web/API/DOMTokenList
  • Revision title: DOMTokenList
  • Revision id: 912173
  • Created:
  • Creator: cvrebert
  • Is current revision? No
  • Comment this is defined in DOM, not HTML

Revision Content

{{APIRef("DOM")}}{{gecko_minversion_header("1.9.2")}}

The DOMTokenList interface represents a set of space-separated tokens. Such a set is returned by {{domxref("Element.classList")}}, {{domxref("HTMLLinkElement.relList")}}, {{domxref("HTMLAnchorElement.relList")}} or {{domxref("HTMLAreaElement.relList")}}. It is indexed beginning with 0 as with JavaScript {{jsxref("Array")}} objects. DOMTokenList is always case-sensitive.

Properties

This interface doesn't inherit any property.

{{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}
Is an integer representing the number of objects stored in the object.

Methods

This interface doesn't inherit any method.

{{domxref("DOMTokenList.item()")}}
Returns an item in the list by its index (or undefined if the number is greater than or equal to the length of the list, prior to {{gecko("7.0")}} returned null)
{{domxref("DOMTokenList.contains()")}}
Returns true if the underlying string contains token, otherwise false
{{domxref("DOMTokenList.add()")}}
Adds token to the underlying string
{{domxref("DOMTokenList.remove()")}}
Removes token from the underlying string
{{domxref("DOMTokenList.toggle()")}}
Removes token from string and returns false. If token doesn't exist it's added and the function returns true

Specifications

Specification Status Comment
{{SpecName("DOM WHATWG", "#interface-domtokenlist", "DOMTokenList")}} {{Spec2("DOM WHATWG")}} Initial definition

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See Also

  • {{domxref("DOMSettableTokenList")}} (object that extends DOMTokenList with settable .value property)
  • {{bug("501257")}} - Implement HTML 5's HTMLElement.classList property

Revision Source

<p>{{APIRef("DOM")}}{{gecko_minversion_header("1.9.2")}}</p>

<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")}} or {{domxref("HTMLAreaElement.relList")}}. 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>

<p><em>This interface doesn't inherit any property.</em></p>

<dl>
 <dt>{{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}</dt>
 <dd>Is an <code>integer</code> representing the number of objects stored in the object.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<p><em>This interface doesn't inherit any method.</em></p>

<dl>
 <dt>{{domxref("DOMTokenList.item()")}}</dt>
 <dd>Returns an item in the list by its index (or undefined if the number is greater than or equal to the length of the list, prior to {{gecko("7.0")}} returned null)</dd>
 <dt>{{domxref("DOMTokenList.contains()")}}</dt>
 <dd>Returns <code>true</code> if the underlying string contains <em>token</em>, otherwise <code>false</code></dd>
 <dt>{{domxref("DOMTokenList.add()")}}</dt>
 <dd>Adds <em>token</em> to the underlying string</dd>
 <dt>{{domxref("DOMTokenList.remove()")}}</dt>
 <dd>Removes <em>token</em> from the underlying string</dd>
 <dt>{{domxref("DOMTokenList.toggle()")}}</dt>
 <dd>Removes <em>token</em> from string and returns false. If <em>token</em> doesn't exist it's added and the function returns true</dd>
</dl>

<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>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_Also">See Also</h2>

<ul>
 <li>{{domxref("DOMSettableTokenList")}} (object that extends DOMTokenList with settable <em>.value</em> property)</li>
 <li>{{bug("501257")}} - Implement HTML 5's HTMLElement.classList property</li>
</ul>
Revert to this revision