DOMTokenList
介面表示了一個以空格作為分隔的內容集,通常來自 Element.classList
、HTMLLinkElement.relList
、HTMLAnchorElement.relList
或 HTMLAreaElement.relList
等屬性。本介面與 Array
同樣是由 0
開始索引,且 DOMTokenList
是區分大小寫的。
屬性
This interface doesn't inherit any property.
DOMTokenList.length
Read only- Is an
integer
representing the number of objects stored in the object.
方法
This interface doesn't inherit any method.
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)
DOMTokenList.contains()
- Returns
true
if the underlying string contains token, otherwisefalse
DOMTokenList.add()
- Adds token to the underlying string
DOMTokenList.remove()
- Removes token from the underlying string
DOMTokenList.replace()
- Replaces an existing token with a new token.
DOMTokenList.supports()
- Returns
true
if a given token is in the associated attribute's supported tokens. 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 |
---|---|---|
DOM The definition of 'DOMTokenList' in that specification. |
Living Standard | Initial definition |
瀏覽器相容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 10 | (Yes) | (Yes) |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | (Yes) | ? | ? | ? | ? | (Yes) |
參見
DOMSettableTokenList
(object that extends DOMTokenList with settable .value property)