---
title: DOMTokenList
slug: Web/API/DOMTokenList
translation_of: Web/API/DOMTokenList
---
{{APIRef("DOM")}}{{gecko_minversion_header("1.9.2")}}
DOMTokenList
介面表示了一個以空格作為分隔的內容集,通常來自 {{domxref("Element.classList")}}、{{domxref("HTMLLinkElement.relList")}}、{{domxref("HTMLAnchorElement.relList")}} 或 {{domxref("HTMLAreaElement.relList")}} 等屬性。本介面與 {{jsxref("Array")}} 同樣是由 0
開始索引,且 DOMTokenList
是區分大小寫的。
屬性
This interface doesn't inherit any property.
- {{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}
- Is an
integer
representing the number of objects stored in the object.
方法
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.replace()")}}
- Replaces an existing token with a new token.
- {{domxref("DOMTokenList.supports()")}}
- Returns
true
if a given token is in the associated attribute's supported tokens.
- {{domxref("DOMTokenList.toggle()")}}
- Removes token from string and returns false. If token doesn't exist it's added and the function returns true
規範
Specification |
Status |
Comment |
{{SpecName("DOM WHATWG", "#interface-domtokenlist", "DOMTokenList")}} |
{{Spec2("DOM WHATWG")}} |
Initial definition |
瀏覽器相容性
{{Compat("api.DOMTokenList")}}
參見
- {{domxref("DOMSettableTokenList")}} (object that extends DOMTokenList with settable .value property)