The DOMTokenList
class, as used by FauxDOM, is only used to implement Node.classList
, even though the standard DOM API uses DOMTokenList
to implement other properties as well (as described on MDN). Therefore, any reference to "tokens" in the below documentation can also be read as "CSS class name". However, for consistency with other, non-FauxDOM documentation, the word "token" continues to be used.
-
length
Number (read-only) — [standard] [MDN]Gets the number of tokens in the list as an integer.
-
value
String — [standard] [MDN]Gets the value of the list as a
String
of all tokens in the list (in list order) separated by single ASCII space characters. Settingvalue
clears the list and, if set to a string value, separates the string treating one or more white space characters in a row as delimiters, with each item in the resulting list (if valid) then being added to thisDOMTokenList
instance.
list.supports( token )
Determines if the specified token can exist in the list (ie. whether token
contains only valid characters or not).
Parameters
-
token
StringThe token to verify.
Return Value
A Boolean
indicating whether the token is valid and can be included in the list.
list.add( token1[, token2[, ...]] )
Adds the specified tokens to the list.
Parameters
-
token...
StringOne or more tokens to add to the list. If a specified token already exists, or isn't valid, it is ignored and nothing happens.
list.contains( token )
Determines if the specified token exists in the list.
Parameters
-
token
StringThe token to check for the existence of in the list.
Return Value
A Boolean
indicating whether the specified token exists in the list.
list.item( index )
Returns the item in the list at the specified numeric index.
Parameters
-
index
NumberThe index of the item in the list you want.
Return Value
The String
item at the specified index, or undefined
if no such index exists.
list.remove( token1[, token2[, ...]] )
Removes the specified tokens from the list.
Parameters
-
token...
StringOne or more tokens to remove from the list. If a specified token doesn't exist, or isn't valid, it is ignored and nothing happens.
list.replace( token, newToken )
Replaces an existing token with a new token.
Parameters
-
token
StringThe token you want to replace.
-
newToken
StringThe token you want to replace
token
with. IfnewToken
is already in the list,token
is simply removed from the list.
Return Value
A Boolean
indicating whether the token token
was successfully replaced by the token newToken
.
list.toggle( token[, force] )
Toggles the existence of the specified token within the list (ie. token
is removed from the list if it exists, otherwise it's added to the list).
Parameters
-
token
StringThe token you want to toggle.
-
force
Boolean (optional)If specified, indicates whether to only add the token (when
force
istrue
), or only remove the token (whenforce
isfalse
).
Return Value
A Boolean
indicating whether token
is in the list after the call to toggle()
.