pub struct Selection<'a> { /* private fields */ }
Expand description
Selection represents a collection of nodes matching some criteria. The
initial Selection object can be created by using [Document::select
], and then
manipulated using methods itself.
Implementations§
source§impl<'a> Selection<'a>
impl<'a> Selection<'a>
sourcepub fn set_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
pub fn set_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
Set the html contents of each element in the selection to specified parsed HTML.
sourcepub fn replace_with_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
pub fn replace_with_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
Replaces each element in the set of matched elements with the parsed HTML. It returns the removed elements.
This follows the same rules as append
.
sourcepub fn replace_with_selection(&mut self, sel: &Selection<'_>)
pub fn replace_with_selection(&mut self, sel: &Selection<'_>)
Replaces each element in the set of matched element with the nodes from the given selection.
This follows the same rules as append
.
sourcepub fn append_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
pub fn append_html<T>(&mut self, html: T)where
T: Into<StrTendril>,
Parses the html and appends it to the set of matched elements.
sourcepub fn append_selection(&mut self, sel: &Selection<'_>)
pub fn append_selection(&mut self, sel: &Selection<'_>)
Appends the elements in the selection to the end of each element in the set of matched elements.
source§impl<'a> Selection<'a>
impl<'a> Selection<'a>
sourcepub fn attr(&self, name: &str) -> Option<StrTendril>
pub fn attr(&self, name: &str) -> Option<StrTendril>
Gets the specified attribute’s value for the first element in the selection. To get the value for each element individually, use a looping construct such as map method.
sourcepub fn attr_or(&self, name: &str, default: &str) -> StrTendril
pub fn attr_or(&self, name: &str, default: &str) -> StrTendril
Works like attr
but returns default value if attribute is not present.
sourcepub fn set_attr(&mut self, name: &str, val: &str)
pub fn set_attr(&mut self, name: &str, val: &str)
Sets the given attribute to each element in the set of matched elements.
sourcepub fn remove_attr(&mut self, name: &str)
pub fn remove_attr(&mut self, name: &str)
Removes the named attribute from each element in the set of matched elements.
sourcepub fn add_class(&mut self, class: &str)
pub fn add_class(&mut self, class: &str)
Adds the given class to each element in the set of matched elements. Multiple class names can be specified, separated by a space via multiple arguments.
sourcepub fn has_class(&self, class: &str) -> bool
pub fn has_class(&self, class: &str) -> bool
Determines whether any of the matched elements are assigned the given class.
sourcepub fn remove_class(&mut self, class: &str)
pub fn remove_class(&mut self, class: &str)
Removes the given class from each element in the set of matched elements. Multiple class names can be specified, separated by a space via multiple arguments.
sourcepub fn html(&self) -> StrTendril
pub fn html(&self) -> StrTendril
Gets the HTML contents of the first element in the set of matched elements. It includes the text and comment nodes.
sourcepub fn text(&self) -> StrTendril
pub fn text(&self) -> StrTendril
Gets the combined text content of each element in the set of matched elements, including their descendants.
source§impl<'a> Selection<'a>
impl<'a> Selection<'a>
sourcepub fn is(&self, sel: &str) -> bool
pub fn is(&self, sel: &str) -> bool
Checks the current matched set of elements against a selector and returns true if at least one of these elements matches.
sourcepub fn is_matcher(&self, matcher: &Matcher) -> bool
pub fn is_matcher(&self, matcher: &Matcher) -> bool
Checks the current matched set of elements against a matcher and returns true if at least one of these elements matches.
sourcepub fn is_selection(&self, sel: &Selection<'_>) -> bool
pub fn is_selection(&self, sel: &Selection<'_>) -> bool
Checks the current matches set of elements against a selection and returns true if at least one of these elements matches.
source§impl<'a> Selection<'a>
impl<'a> Selection<'a>
sourcepub fn select<'b>(&self, sel: &'b str) -> Selection<'a>where
'a: 'b,
pub fn select<'b>(&self, sel: &'b str) -> Selection<'a>where
'a: 'b,
Gets the descendants of each element in the current set of matched elements, filter by a selector. It returns a new Selection object containing these matched elements.
§Panics
Panics if failed to parse the given CSS selector.
sourcepub fn select_matcher(&self, matcher: &Matcher) -> Selection<'a>
pub fn select_matcher(&self, matcher: &Matcher) -> Selection<'a>
Gets the descendants of each element in the current set of matched elements, filter by a matcher. It returns a new Selection object containing these matched elements.
sourcepub fn nip(&self, sel: &'a str) -> Selection<'a>
pub fn nip(&self, sel: &'a str) -> Selection<'a>
Alias for select
, it gets the descendants of each element in the current set of matched
elements, filter by a selector. It returns a new Selection object
containing these matched elements.
§Panics
Panics if failed to parse the given CSS selector.
sourcepub fn try_select(&self, sel: &str) -> Option<Selection<'a>>
pub fn try_select(&self, sel: &str) -> Option<Selection<'a>>
Gets the descendants of each element in the current set of matched elements, filter by a selector. It returns a new Selection object containing these matched elements.
sourcepub fn iter(&self) -> Selections<Node<'a>> ⓘ
pub fn iter(&self) -> Selections<Node<'a>> ⓘ
Creates an iterator over these matched elements.
sourcepub fn parent(&self) -> Selection<'a>
pub fn parent(&self) -> Selection<'a>
Gets the parent of each element in the selection. It returns a mew Selection object containing these elements.
sourcepub fn children(&self) -> Selection<'a>
pub fn children(&self) -> Selection<'a>
Gets the child elements of each element in the selection. It returns a new Selection object containing these elements.
sourcepub fn next(&self) -> Selection<'a>
👎Deprecated since 0.1.6: Please use next_sibling
pub fn next(&self) -> Selection<'a>
next_sibling
Gets the immediately following sibling of each element in the selection. It returns a new Selection object containing these elements.
sourcepub fn next_sibling(&self) -> Selection<'a>
pub fn next_sibling(&self) -> Selection<'a>
Gets the immediately following sibling of each element in the selection. It returns a new Selection object containing these elements.
sourcepub fn prev_sibling(&self) -> Selection<'a>
pub fn prev_sibling(&self) -> Selection<'a>
Gets the immediately previous sibling of each element in the selection. It returns a new Selection object containing these elements.
sourcepub fn first(&self) -> Selection<'a>
pub fn first(&self) -> Selection<'a>
Reduces the set of matched elements to the first in the set. It returns a new selection object, and an empty selection object if the selection is empty.