Struct dom_query::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 elements against a selection and returns true if at least one of these elements matches.

source§

impl<'a> Selection<'a>

source

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.

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

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 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 copy 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() -> Selection<'a>

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

§

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

§

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

§

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.