pub struct DomNode { /* private fields */ }
Expand description
Rendering backend for the DOM.
This API requires the following crate features to be activated: dom
Implementations
impl DomNode
impl DomNode
pub fn inner_element(&self) -> Node
pub fn inner_element(&self) -> Node
Get the underlying [web_sys::Node
].
pub fn unchecked_into<T>(self) -> T where
T: JsCast,
pub fn unchecked_into<T>(self) -> T where
T: JsCast,
Cast the underlying [web_sys::Node
] using JsCast
.
pub fn from_web_sys(node: Node) -> DomNode
pub fn from_web_sys(node: Node) -> DomNode
Create a new DomNode
from a raw [web_sys::Node
].
Trait Implementations
impl GenericNode for DomNode
impl GenericNode for DomNode
type PropertyType = JsValue
type PropertyType = JsValue
The type for set_property
.
fn element_from_tag(tag: &str) -> DomNode
fn element_from_tag(tag: &str) -> DomNode
Create a new element node from a tag string.
fn text_node_int(int: i32) -> DomNode
fn text_node_int(int: i32) -> DomNode
Create a new text node from an integer.
fn marker_with_text(text: &str) -> DomNode
fn marker_with_text(text: &str) -> DomNode
Create a marker (dummy) node with text content. For empty marker, prefer
[GenericNode::marker
] instead. Read more
fn set_attribute(&self, name: &str, value: &str)
fn set_attribute(&self, name: &str, value: &str)
Sets an attribute on a node.
fn remove_attribute(&self, name: &str)
fn remove_attribute(&self, name: &str)
Removes an attribute on a node.
fn set_class_name(&self, value: &str)
fn set_class_name(&self, value: &str)
Sets the class
attribute on a node.
This should have the same outcome as calling set_attribute("class", value)
.
For DomNode
, this sets the className
property directly which is about 2x faster (on
Chrome). Read more
fn add_class(&self, class: &str)
fn add_class(&self, class: &str)
Add a class to the element. If multiple classes are specified, delimited by spaces, all the classes should be added. Any classes that are already present should not be added a second time. Read more
fn remove_class(&self, class: &str)
fn remove_class(&self, class: &str)
Remove a class from the element.
fn set_property(&self, name: &str, value: &JsValue)
fn set_property(&self, name: &str, value: &JsValue)
Sets a property on a node.
fn remove_property(&self, name: &str)
fn remove_property(&self, name: &str)
Removes a property on a node.
fn append_child(&self, child: &DomNode)
fn append_child(&self, child: &DomNode)
Appends a child to the node’s children.
fn first_child(&self) -> Option<DomNode>
fn first_child(&self) -> Option<DomNode>
Get the first child of the node.
fn insert_child_before(
&self,
new_node: &DomNode,
reference_node: Option<&DomNode>
)
fn insert_child_before(
&self,
new_node: &DomNode,
reference_node: Option<&DomNode>
)
Insert a new child node to this node’s children. If reference_node
is Some
, the child
will be inserted before the reference node. Else if None
, the child will be inserted
at the end. Read more
fn remove_child(&self, child: &DomNode)
fn remove_child(&self, child: &DomNode)
Remove a child node from this node’s children.
fn replace_child(&self, old: &DomNode, new: &DomNode)
fn replace_child(&self, old: &DomNode, new: &DomNode)
Replace a child node from this node’s children with a new child node.
fn insert_sibling_before(&self, child: &DomNode)
fn insert_sibling_before(&self, child: &DomNode)
Insert a new node before this node.
fn parent_node(&self) -> Option<DomNode>
fn parent_node(&self) -> Option<DomNode>
Returns the parent node, or None
if detached.
fn next_sibling(&self) -> Option<DomNode>
fn next_sibling(&self) -> Option<DomNode>
Returns the next sibling, or None
if this node is the last sibling.
fn remove_self(&self)
fn remove_self(&self)
Remove this node from the tree.
fn event<'a, F>(&self, cx: BoundedScope<'a, 'a>, name: &str, handler: F) where
F: 'a + FnMut(<DomNode as GenericNode>::EventType),
fn event<'a, F>(&self, cx: BoundedScope<'a, 'a>, name: &str, handler: F) where
F: 'a + FnMut(<DomNode as GenericNode>::EventType),
Add a event handler to the event name
.
fn update_inner_text(&self, text: &str)
fn update_inner_text(&self, text: &str)
Update inner text of the node. If the node has elements, all the elements are replaced with a new text node. Read more
fn dangerously_set_inner_html(&self, html: &str)
fn dangerously_set_inner_html(&self, html: &str)
Updates the inner html of the node.
The html will not be parsed in non-browser environments. This means that accessing methods
such as first_child
will return None
. Read more
fn clone_node(&self) -> DomNode
fn clone_node(&self) -> DomNode
Create a deep clone of the node.
const USE_HYDRATION_CONTEXT: bool = false
const USE_HYDRATION_CONTEXT: bool = false
Whether this rendering backend needs the hydration registry.
const CLIENT_SIDE_HYDRATION: bool = false
const CLIENT_SIDE_HYDRATION: bool = false
Whether this rendering backend hydrates nodes on the client side.
fn marker() -> Self
fn marker() -> Self
Create a marker (dummy) node. For DomNode
, this is implemented by creating an empty
comment node. This is used, for example, in Keyed
and Indexed
for scenarios where you
want to push a new item to the end of the list. If the list is empty, a dummy node is
needed to store the position of the component. Read more
impl Html for DomNode
impl Html for DomNode
const IS_BROWSER: bool = true
const IS_BROWSER: bool = true
A boolean indicating whether this node is rendered in a browser context. Read more
impl PartialEq<DomNode> for DomNode
impl PartialEq<DomNode> for DomNode
impl Eq for DomNode
Auto Trait Implementations
impl !RefUnwindSafe for DomNode
impl !Send for DomNode
impl !Sync for DomNode
impl Unpin for DomNode
impl UnwindSafe for DomNode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.