Selector.find Method

Returns descendant nodes that match the specified CSS Selector or filter function.



Selector().find(cssSelector) → Selector

Returns descendant nodes that match the specified CSS Selector.

Argument Type Description
cssSelector String CSS Selector.

find(filterFn, dependencies)

Selector().find(filterFn, dependencies) → Selector

Filters element descendants with a function.

Argument Type Description
filterFn Function Filter function.
dependencies (optional) Object Functions, variables, or objects passed to the filterFn function.

See Filter DOM With A Function.


// Selects input elements that are descendants
// of div elements with the col-1 class.
const foundSelector = Selector('div.col-1').find('input');

Filter DOM with a function

To filter the DOM with a client-side filter function, pass a function argument to the method.

The filterFn argument accepts the following parameters:

Parameter Description
node The current node.
idx The index of the current node.
originNode The DOM Node .
Selector('section').prevSibling((node, idx, originNode) => {
    // node === the <section>'s preceding sibling node
    // idx === index of the current <section>'s preceding sibling node
    // originNode === the <section> element

Use the dependencies option to pass variables to the filter function.

const isNodeOk = (node, idx, originNode) => {
    console.log({ node, idx, originNode });
    return idx === 6;

const filteredDiv = Selector('div').prevSibling((node) => {
    return !isNaN(node.textContent);
}, { isNodeOk });