pub trait ElementExt {
Show 16 methods
// Required methods
fn set_class(&self, class: &str);
fn set_id(&self, id: &str);
fn set_text(&self, text: &str);
fn set_html(&self, html: &str) -> Result<(), JsValue>;
fn set_attr(&self, attr: &str, value: &str) -> Result<(), JsValue>;
fn get_attr(&self, attr: &str) -> Option<String>;
fn remove_attr(&self, attr: &str) -> Result<(), JsValue>;
fn add_class(&self, class: &str) -> Result<(), JsValue>;
fn remove_class(&self, class: &str) -> Result<(), JsValue>;
fn toggle_class(&self, class: &str) -> Result<(), JsValue>;
fn has_class(&self, class: &str) -> bool;
fn on<F>(&self, event: &str, handler: F) -> Result<(), JsValue>
where F: FnMut(Event) + 'static;
fn append(&self, child: &Element) -> Result<(), JsValue>;
fn prepend(&self, child: &Element) -> Result<(), JsValue>;
fn remove(&self) -> Result<(), JsValue>;
fn clear(&self);
}Expand description
Ergonomic extension methods for web_sys::Element.
Provides concise helpers for common DOM manipulations (attributes, classes,
text/HTML content, event listeners, and child insertion/removal) on top of
the lower-level web-sys API.
Required Methods§
Sourcefn set_html(&self, html: &str) -> Result<(), JsValue>
fn set_html(&self, html: &str) -> Result<(), JsValue>
Replaces the element’s inner HTML with html.
Sourcefn set_attr(&self, attr: &str, value: &str) -> Result<(), JsValue>
fn set_attr(&self, attr: &str, value: &str) -> Result<(), JsValue>
Sets attribute attr to value.
Sourcefn get_attr(&self, attr: &str) -> Option<String>
fn get_attr(&self, attr: &str) -> Option<String>
Returns the value of attribute attr, or None if it is absent.
Sourcefn add_class(&self, class: &str) -> Result<(), JsValue>
fn add_class(&self, class: &str) -> Result<(), JsValue>
Adds class to the class attribute if it is not already present.
Sourcefn remove_class(&self, class: &str) -> Result<(), JsValue>
fn remove_class(&self, class: &str) -> Result<(), JsValue>
Removes class from the class attribute, dropping the attribute
entirely when no classes remain.
Sourcefn toggle_class(&self, class: &str) -> Result<(), JsValue>
fn toggle_class(&self, class: &str) -> Result<(), JsValue>
Adds class if absent, or removes it if present.
Sourcefn has_class(&self, class: &str) -> bool
fn has_class(&self, class: &str) -> bool
Returns true if the class attribute contains class as a whole
token.
Sourcefn on<F>(&self, event: &str, handler: F) -> Result<(), JsValue>
fn on<F>(&self, event: &str, handler: F) -> Result<(), JsValue>
Attaches handler as a listener for event.
The underlying closure is leaked so the listener remains valid for the lifetime of the element.
Sourcefn append(&self, child: &Element) -> Result<(), JsValue>
fn append(&self, child: &Element) -> Result<(), JsValue>
Appends child as the last child of this element.
Sourcefn prepend(&self, child: &Element) -> Result<(), JsValue>
fn prepend(&self, child: &Element) -> Result<(), JsValue>
Inserts child as the first child of this element, or appends it when
the element has no children.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".