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
| Name | Type | Access | Description |
|---|---|---|---|
value | str | Read/Write | The raw attribute value string, or '' if the attribute is absent. |
length | int | Read | The number of tokens in the list (read-only). |
Methods
| Signature | Description |
|---|---|
__init__(owner_element: "Element", attr_name: str) | Initialise the list by storing owner and attribute name only. |
contains(token: str) → bool | Return 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 | None | Return 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) → bool | Add or remove token, returning its new presence state. |
replace(old_token: str, new_token: str) → bool | Replace 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) → bool | Raise TypeError — no supported-tokens list exists for the class attribute. |