Selection

Struct Selection 

Source
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>

Source

pub fn remove(&mut self)

Removes the set of matched elements from the document.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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.

Source

pub fn attr_or(&self, name: &str, default: &str) -> StrTendril

Works like attr but returns default value if attribute is not present.

Source

pub fn set_attr(&mut self, name: &str, val: &str)

Sets the given attribute to each element in the set of matched elements.

Source

pub fn remove_attr(&mut self, name: &str)

Removes the named attribute from each element in the set of matched elements.

Source

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.

Source

pub fn has_class(&self, class: &str) -> bool

Determines whether any of the matched elements are assigned the given class.

Source

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.

Source

pub fn length(&self) -> usize

Returns the number of elements in the selection object.

Source

pub fn size(&self) -> usize

Is an alias for length.

Source

pub fn exists(&self) -> bool

Is there any matched elements.

Source

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.

Source

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>

Source

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.

Source

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.

Source

pub fn is_selection(&self, sel: &Selection<'_>) -> bool

Checks the current matches set of elemets against a selection and returns true if at least one of these elements matches.

Source§

impl<'a> Selection<'a>

Source

pub fn select(&self, sel: &str) -> 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.

§Panics

Panics if failed to parse the given CSS selector.

Source

pub fn nip(&self, sel: &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.

Source

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.

Source

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.

Source

pub fn nodes(&self) -> &[Node<'a>]

Returns a slice of underlying nodes.

Source

pub fn iter(&self) -> Selections<Node<'a>>

Creates an iterator over these matched elements.

Source

pub fn parent(&self) -> Selection<'a>

Gets the parent of each element in the selection. It returns a mew Selection object containing these elements.

Source

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.

Source

pub fn next(&self) -> Selection<'a>

👎Deprecated since 0.1.6: Please use next_sibling

Gets the immediately following sibling of each element in the selection. It returns a new Selection object containing these elements.

Source

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.

Source

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.

Source

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.

Source

pub fn last(&self) -> Selection<'a>

Reduces the set of matched elements to the last in the set. It returns a new selection object, and an empty selection object if the selection is empty.

Source

pub fn get(&self, index: usize) -> Option<&Node<'a>>

Retrieves the underlying node at the specified index.

Trait Implementations§

Source§

impl<'a> Clone for Selection<'a>

Source§

fn clone(&self) -> Selection<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Selection<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for Selection<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> From<NodeRef<'a, NodeData>> for Selection<'a>

Source§

fn from(node: Node<'a>) -> Selection<'_>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Selection<'a>

§

impl<'a> !RefUnwindSafe for Selection<'a>

§

impl<'a> !Send for Selection<'a>

§

impl<'a> !Sync for Selection<'a>

§

impl<'a> Unpin for Selection<'a>

§

impl<'a> !UnwindSafe for Selection<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.