Interface DOMTokenList


@JsType(isNative=true, namespace="<global>") public interface DOMTokenList
A GWT wrapper for the native JavaScript DOMTokenList interface.

This represents a set of space-separated tokens, primarily used for the part property of an HTML element, allowing for manipulation of its CSS classes.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String... token)
    Adds the given token to the list.
    boolean
    Returns a boolean value indicating whether the list contains the given token.
    int
    Gets the number of tokens in the list.
    Gets the string representation of the token list.
    void
    remove(String token)
    Removes the given token from the list.
    boolean
    replace(String oldToken, String newToken)
    Replaces an existing token with a new token.
    boolean
    toggle(String token)
    Removes the given token from the list if it is present, and adds it if it is not.
    boolean
    toggle(String token, boolean force)
    Turns the toggle into a one way-only operation.
  • Method Details

    • add

      void add(String... token)
      Adds the given token to the list.

      If the token already exists in the list, it is not added again.

      Parameters:
      token - The token to add to the list.
    • remove

      void remove(String token)
      Removes the given token from the list. If the token does not exist in the list, no action is taken.
      Parameters:
      token - The string token to remove from the list.
    • contains

      boolean contains(String token)
      Returns a boolean value indicating whether the list contains the given token.
      Parameters:
      token - The string token to check for.
      Returns:
      true if the token is found, otherwise false.
    • toggle

      boolean toggle(String token)
      Removes the given token from the list if it is present, and adds it if it is not.
      Parameters:
      token - The token to toggle.
      Returns:
      true if the token is now present in the list, and false otherwise.
    • toggle

      boolean toggle(String token, boolean force)
      Turns the toggle into a one way-only operation. If the `force` parameter is true, this method adds the specified token if it's not already present. If `force` is false, it removes the token if it is present.
      Parameters:
      token - The token to toggle.
      force - If true, the token is added. If false, the token is removed.
      Returns:
      true if the token is now present in the list, and false otherwise.
    • replace

      boolean replace(String oldToken, String newToken)
      Replaces an existing token with a new token.

      If the token to replace is not found in the list, this method does nothing and returns false. If the token is found, it is replaced by the new token and the method returns true.

      Parameters:
      oldToken - The token to be replaced.
      newToken - The new token.
      Returns:
      true if the replacement was successful, false otherwise.
    • getLength

      @JsProperty int getLength()
      Gets the number of tokens in the list.
      Returns:
      the number of tokens.
    • getValue

      @JsProperty String getValue()
      Gets the string representation of the token list.
      Returns:
      a space-separated string containing all the tokens in the list.