class Selector

Description

A class that queries the document for elements that match a given CSS selector.

Related utilities

$$

Constructor

new Selector(expression)
  • expression (String) – A CSS selector.

Creates a Selector with the given CSS selector.

Class methods

  • findChildElements #

    Selector.findChildElements(element, expressions) ⇒ [Element…]

    Searches beneath element for any elements that match the selector (or selectors) specified in expressions.

  • findElement #

    Selector.findElement(elements, expression[, index = 0]) ⇒ Element
    Selector.findElement(elements[, index = 0]) ⇒ Element

    Returns the indexth element in the collection that matches expression.

    Returns the indexth element overall if expression is not given.

  • matchElements #

    Selector.matchElements(elements, expression) ⇒ [Element…]

    Filters the given collection of elements with expression.

    The only nodes returned will be those that match the given CSS selector.

  • split #

    Selector.split(expression) ⇒ [String…]

    Takes a string of CSS selectors separated by commas; returns an array of individual selectors.

    Safer than doing a naive Array#split, since selectors can have commas in other places.

Instance methods

  • findElements #

    Selector#findElements(root) ⇒ [Element…]
    • root (Element || document): A "scope" to search within. All results will be descendants of this node.

    Searches the document for elements that match the instance's CSS selector.

  • match #

    Selector#match(element) ⇒ Boolean

    Tests whether a element matches the instance's CSS selector.