Skip to content

Latest commit

 

History

History
187 lines (107 loc) · 5.46 KB

DOMTokenList.md

File metadata and controls

187 lines (107 loc) · 5.46 KB

DOMTokenList

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.

Table of Contents

Properties

  • 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. Setting value 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 this DOMTokenList instance.

Methods

Semi-standard

list.supports( token )

[standard] [MDN]

Determines if the specified token can exist in the list (ie. whether token contains only valid characters or not).

Parameters

  • token String

    The token to verify.

Return Value

A Boolean indicating whether the token is valid and can be included in the list.


Standard

list.add( token1[, token2[, ...]] )

[standard] [MDN]

Adds the specified tokens to the list.

Parameters

  • token... String

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

[standard] [MDN]

Determines if the specified token exists in the list.

Parameters

  • token String

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

[standard] [MDN]

Returns the item in the list at the specified numeric index.

Parameters

  • index Number

    The 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[, ...]] )

[standard] [MDN]

Removes the specified tokens from the list.

Parameters

  • token... String

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

[standard] [MDN]

Replaces an existing token with a new token.

Parameters

  • token String

    The token you want to replace.

  • newToken String

    The token you want to replace token with. If newToken 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] )

[standard] [MDN]

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 String

    The token you want to toggle.

  • force Boolean (optional)

    If specified, indicates whether to only add the token (when force is true), or only remove the token (when force is false).

Return Value

A Boolean indicating whether token is in the list after the call to toggle().