pub struct Element { /* private fields */ }Expand description
An HTML element.
The element has a Tag, possibly some attributes, and possibly
some children. It may also have a location: this is used when the
element is constructed by parsing some input value.
Implementations§
source§impl Element
impl Element
sourcepub fn with_location(self, line: usize, col: usize) -> Self
pub fn with_location(self, line: usize, col: usize) -> Self
Set the location of an element in a source file.
sourcepub fn with_child(self, child: Element) -> Self
pub fn with_child(self, child: Element) -> Self
Append a child element, when constructing.
sourcepub fn with_attribute(self, name: &str, value: &str) -> Self
pub fn with_attribute(self, name: &str, value: &str) -> Self
Set an attribute when creating an element.
sourcepub fn with_boolean_attribute(self, name: &str) -> Self
pub fn with_boolean_attribute(self, name: &str) -> Self
Set a boolean attribute when creating an element.
sourcepub fn with_class(self, class: &str) -> Self
pub fn with_class(self, class: &str) -> Self
Add a class when creating an element.
sourcepub fn attributes(&self) -> impl Iterator<Item = &str>
pub fn attributes(&self) -> impl Iterator<Item = &str>
Return an iterator over the names of the attributes of an element.
sourcepub fn attribute(&self, name: &str) -> Option<&AttributeValue>
pub fn attribute(&self, name: &str) -> Option<&AttributeValue>
Return the value of an attribute, if the attribute is set.
Otherwise, return None.
sourcepub fn attribute_value(&self, name: &str) -> Option<&str>
pub fn attribute_value(&self, name: &str) -> Option<&str>
Return the value of an attribute as text, if the attribute is
set. Otherwise, return None.
sourcepub fn set_attribute(&mut self, name: &str, value: &str)
pub fn set_attribute(&mut self, name: &str, value: &str)
Set a key/value attribute. If the attribute was already set, change the value it has.
sourcepub fn set_boolean_attribute(&mut self, name: &str)
pub fn set_boolean_attribute(&mut self, name: &str)
Set a boolean attribute.
sourcepub fn unset_attribute(&mut self, name: &str)
pub fn unset_attribute(&mut self, name: &str)
Remove an attribute, which can be key/value or boolean.
sourcepub fn classes(&self) -> impl Iterator<Item = &str>
pub fn classes(&self) -> impl Iterator<Item = &str>
Return current classes set directly for this element.
sourcepub fn add_class(&mut self, class: &str)
pub fn add_class(&mut self, class: &str)
Add a class to the element. This does not replace existing classes.
sourcepub fn push_text(&mut self, text: &str)
pub fn push_text(&mut self, text: &str)
Append text to element. It will be escaped, if needed, when the element is serialized.
sourcepub fn push_child(&mut self, child: Element)
pub fn push_child(&mut self, child: Element)
Append a child element to this element.
sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
Remove all children.
sourcepub fn push_html(&mut self, html: &str)
pub fn push_html(&mut self, html: &str)
Append HTML to element. It will NOT be escaped, when the element is serialized.
sourcepub fn plain_text(&self) -> String
pub fn plain_text(&self) -> String
Return all the textual content in an element and its children. This does not include attributes.