dom
wybthon.dom¶
Lightweight DOM wrapper utilities for Pyodide/browser environments.
Element
¶
Thin wrapper around a DOM node with convenience methods.
add_class(*class_names)
¶
Add one or more CSS classes to this element.
append(child)
¶
Append a child Element or a text node to this element.
append_to(parent)
¶
Append this element to the given parent element.
attach_ref(ref)
¶
Attach this element to a mutable Ref container.
cleanup()
¶
Remove all tracked event listeners from this element.
find(selector)
¶
Find the first matching descendant by CSS selector.
find_all(selector)
¶
Find all matching descendants by CSS selector.
get_attr(name)
¶
Return attribute value or None when missing.
has_class(class_name)
¶
Return True if the element currently has the given class.
load_html(url)
async
¶
Fetch HTML from url and set as innerHTML of this element.
off(event_type=None, handler=None)
¶
Remove matching event listeners previously attached via on().
on(event_type, handler, *, options=None)
¶
Add an event listener and track it for cleanup.
query(selector, within=None)
classmethod
¶
Query a single element by CSS selector, optionally within a parent.
query_all(selector, within=None)
classmethod
¶
Query all matching elements by CSS selector, optionally within a parent.
remove()
¶
Remove this element from its parent if attached.
remove_attr(name)
¶
Remove an attribute from this element.
remove_class(*class_names)
¶
Remove one or more CSS classes from this element.
set_attr(name, value)
¶
Set an attribute on this element, with text-node fallbacks.
set_html(html)
¶
Set the innerHTML of this element to the provided HTML string.
set_style(styles=None, **style_kwargs)
¶
Set CSS properties using a dict and/or keyword arguments.
set_text(text)
¶
Set text content for this element.
toggle_class(class_name, force=None)
¶
Toggle a CSS class, optionally forcing on/off.
Ref
¶
Mutable container holding a reference to an Element.