DOMTokenList

Overview

DOMTokenList is a class in Aspose.Html FOSS for Python.

A live, mutable set of space-separated tokens backed by an element attribute.

This class provides 12 methods for working with DOMTokenList objects in Python programs. Available methods include: __init__, add, contains, entries, for_each, item, keys, remove, replace, supports, toggle, values. All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package. Properties: length, value.

Properties

NameTypeAccessDescription
valuestrRead/WriteThe raw attribute value string, or '' if the attribute is absent.
lengthintReadThe number of tokens in the list (read-only).

Methods

SignatureDescription
__init__(owner_element: "Element", attr_name: str)Initialise the list by storing owner and attribute name only.
contains(token: str)boolReturn True if token is present in the token list.
values()Iterator[str]Return an iterator over the tokens in attribute order.
item(index: int)str | NoneReturn the token at index, or None if index is out of bounds.
add()Add one or more tokens.
remove()Remove one or more tokens.
toggle(token: str, force: bool | None)boolAdd or remove token, returning its new presence state.
replace(old_token: str, new_token: str)boolReplace old_token with new_token in-place.
entries()Iterator[tuple[int, str]]Return an iterator of (index, token) pairs, in attribute order.
keys()Iterator[int]Return an iterator of integer indices 0, 1, …, len-1.
for_each(callback: Callable[["str", int, "DOMTokenList"], None])Call callback once for each token in attribute order.
supports(token: str)boolRaise TypeError — no supported-tokens list exists for the class attribute.

See Also