pub struct DomElement { /* private fields */ }Expand description
A DOM element.
Implementations§
Source§impl DomElement
impl DomElement
Sourcepub fn set_attribute(&self, key: &str, value: &str)
pub fn set_attribute(&self, key: &str, value: &str)
Set an attribute on the DOM element.
Sourcepub fn remove_attribute(&self, key: &str)
pub fn remove_attribute(&self, key: &str)
Remove an attribute from the DOM element.
Source§impl DomElement
impl DomElement
Source§impl DomElement
impl DomElement
Sourcepub fn dialog_show_modal(&self)
pub fn dialog_show_modal(&self)
Open the dialog element as a modal
TODO: Consider having more type safety to reduce the likelihood of calling this on something that isn’t a dialog. One possible idea would be to have a DialogElement type and put the show_modal and close methods on the DialogElement type and then have a way to cast between types.
Sourcepub fn dialog_close(&self)
pub fn dialog_close(&self)
Close the dialog element as a modal
Source§impl DomElement
impl DomElement
Sourcepub fn append_child(&self, child: &impl AsDomNode)
pub fn append_child(&self, child: &impl AsDomNode)
Append a child node to this element’s list of children.
Source§impl DomElement
impl DomElement
Sourcepub fn maybe_new(
handle: i64,
component_imports: ComponentImports,
) -> Option<Self>
pub fn maybe_new( handle: i64, component_imports: ComponentImports, ) -> Option<Self>
If the handle is 0, returns None.
Otherwise, returns a DomElement.
Sourcepub fn temporary_way_to_get_i64(&self) -> i64
pub fn temporary_way_to_get_i64(&self) -> i64
Will be deleted once we stop using it.
Sourcepub fn do_not_use_this_for_new_stuff_temporary_public_way_to_create_using_existing_i64_handle(
&self,
element_handle: i64,
) -> Option<Self>
pub fn do_not_use_this_for_new_stuff_temporary_public_way_to_create_using_existing_i64_handle( &self, element_handle: i64, ) -> Option<Self>
Adding this because some of our older components are using older patterns and this will help
with migrating them towards using this afia-component crate.
DO NOT use this. It was introduced in the middle of a huge PR to help avoid needing to
refctor everything at once.
Sourcepub fn set_text_content(&self, text: &str)
pub fn set_text_content(&self, text: &str)
Set the text content of this element.
Sourcepub fn previous_element_sibling(&self) -> Option<DomElement>
pub fn previous_element_sibling(&self) -> Option<DomElement>
Get this element’s previous element sibling.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/Element/previousElementSibling
Sourcepub fn next_element_sibling(&self) -> Option<DomElement>
pub fn next_element_sibling(&self) -> Option<DomElement>
Get this element’s next element sibling.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/Element/nextElementSibling
Sourcepub fn tag_name(&self) -> String
pub fn tag_name(&self) -> String
Get the element’s tag name, such as “DIV” or “SPAN”.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName
Sourcepub fn click(&self)
pub fn click(&self)
Simulate a click on the element.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click
Sourcepub fn child_nodes(&self) -> NodeList
pub fn child_nodes(&self) -> NodeList
Get the element’s child nodes.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes
Sourcepub fn get_attribute(&self, key: &str) -> Option<String>
pub fn get_attribute(&self, key: &str) -> Option<String>
Get one of the element’s attributes.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
Sourcepub fn inner_text(&self) -> String
pub fn inner_text(&self) -> String
Get the DOM element’s inner text.
§MDN Documentation
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
Source§impl DomElement
impl DomElement
Sourcepub fn add_event_listener_with_callback(
&self,
event_name: &str,
context: &'static Callback,
) -> i64
pub fn add_event_listener_with_callback( &self, event_name: &str, context: &'static Callback, ) -> i64
Attach an event listener to this DOM element.
TODO: We are still experimenting with event handling so we currently have multiple methods in this file for adding event listeners. We can eventually figure out our patterns, document these patterns, then delete methods that do not fit within these patterns.
Sourcepub fn add_event_listener_boxed(
&self,
event_name: &str,
callback: Box<dyn FnMut()>,
) -> i64
pub fn add_event_listener_boxed( &self, event_name: &str, callback: Box<dyn FnMut()>, ) -> i64
Attach an event listener to a DOM element.
TODO: We are still experimenting with event handling so we currently have multiple methods in this file for adding event listeners. We can eventually figure out our patterns, document these patterns, then delete methods that do not fit within these patterns.
Source§impl DomElement
impl DomElement
Sourcepub fn get_property_string<'out>(
&self,
key: &str,
out_buffer: &'out mut [u8],
) -> Result<&'out str, DomNodeGetPropertyStringError>
pub fn get_property_string<'out>( &self, key: &str, out_buffer: &'out mut [u8], ) -> Result<&'out str, DomNodeGetPropertyStringError>
Get DOM node’s property. The property is expected to have a string value, otherwise an error is returned.
Sourcepub fn get_property_bool<'out>(
&self,
key: &str,
) -> Result<bool, DomNodeGetPropertyBoolError>
pub fn get_property_bool<'out>( &self, key: &str, ) -> Result<bool, DomNodeGetPropertyBoolError>
Get DOM node’s property. The property is expected to have a bool value, otherwise an error is returned.
Sourcepub fn set_property_string(&self, key: &str, value: &str)
pub fn set_property_string(&self, key: &str, value: &str)
Set DOM node’s property to a string value.
Sourcepub fn set_property_bool(&self, key: &str, value: bool)
pub fn set_property_bool(&self, key: &str, value: bool)
Set DOM node’s property to a boolean value.
Trait Implementations§
Source§impl AsDomNode for DomElement
impl AsDomNode for DomElement
Source§impl Clone for DomElement
impl Clone for DomElement
Source§fn clone(&self) -> DomElement
fn clone(&self) -> DomElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more