QueryWrapper

QueryWrapper

Wrap a NodeWrapper with chainable traversal/modification functions

Constructor

new QueryWrapper(nodes)

Create a new QueryWrapper

Parameters:
Name Type Description
nodes Array.<NodeWrapper>
Source:

Methods

after(node) → {QueryWrapper}

Insert a node after each node in the set of matched nodes

Parameters:
Name Type Description
node object
Source:
Returns:
Type
QueryWrapper

before(node) → {QueryWrapper}

Insert a node before each node in the set of matched nodes

Parameters:
Name Type Description
node object
Source:
Returns:
Type
QueryWrapper

children(selectoropt) → {QueryWrapper}

Get the children of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

closest(selectoropt) → {QueryWrapper}

For each node in the set of matched nodes, get the first node that matches the selector by testing the node itself and traversing up through its ancestors

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

concat(wrapper) → {any}

Combine the nodes of two QueryWrappers

Parameters:
Name Type Description
wrapper QueryWrapper
Source:
Returns:
Type
any

eq(index) → {QueryWrapper}

Reduce the set of matched nodes to the one at the specified index

Parameters:
Name Type Description
index number
Source:
Returns:
Type
QueryWrapper

filter(selectoropt) → {QueryWrapper}

Reduce the set of matched nodes to those that match the selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

find(selectoropt) → {QueryWrapper}

Get the descendants of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

first() → {QueryWrapper}

Reduce the set of matched nodes to the first in the set.

Source:
Returns:
Type
QueryWrapper

get(indexopt) → {object|Array.<object>}

Return the wrapper as a JSON node or array of JSON nodes

Parameters:
Name Type Attributes Description
index number <optional>
Source:
Returns:
Type
object | Array.<object>

has(selectoropt) → {QueryWrapper}

Reduce the set of matched nodes to those that have a descendant that matches the selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

hasParent(selectoropt) → {QueryWrapper}

Reduce the set of matched nodes to those that have a parent that matches the selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

hasParents(selectoropt) → {QueryWrapper}

Reduce the set of matched nodes to those that have an ancestor that matches the selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

index(nodeopt) → {number}

Search for a given node in the set of matched nodes.

If no argument is passed, the return value is an integer indicating the position of the first node within the Wrapper relative to its sibling nodes.

If called on a collection of nodes and a NodeWrapper is passed in, the return value is an integer indicating the position of the passed NodeWrapper relative to the original collection.

If a selector is passed as an argument, the return value is an integer indicating the position of the first node within the Wrapper relative to the nodes matched by the selector.

If the selctor doesn't match any nodes, it will return -1.

Parameters:
Name Type Attributes Description
node NodeWrapper | Wrapper~Selector <optional>
Source:
Returns:
Type
number

last() → {QueryWrapper}

Reduce the set of matched nodes to the final one in the set

Source:
Returns:
Type
QueryWrapper

length() → {number}

Return the number of nodes in the wrapper

Source:
Returns:
Type
number

map(fn) → {array}

Map the set of matched nodes

Parameters:
Name Type Description
fn function
Source:
Returns:
Type
array

next(selectoropt) → {QueryWrapper}

Get the immediately following sibling of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

nextAll(selectoropt) → {QueryWrapper}

Get all following siblings of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

parent(selectoropt) → {QueryWrapper}

Get the parent of each nodes in the current set of matched nodess, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

parents(selectoropt) → {QueryWrapper}

Get the ancestors of each nodes in the current set of matched nodess, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

parentsUntil(selectoropt) → {QueryWrapper}

Get the ancestors of each node in the set of matched nodes, up to but not including the node matched by the selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

prev(selectoropt) → {QueryWrapper}

Get the immediately preceding sibling of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

prevAll(selectoropt) → {QueryWrapper}

Get all preceding siblings of each node in the set of matched nodes, optionally filtered by a selector

Parameters:
Name Type Attributes Description
selector Wrapper~Selector <optional>
Source:
Returns:
Type
QueryWrapper

reduce(fn, acc) → {any}

Reduce the set of matched nodes

Parameters:
Name Type Description
fn function
acc any
Source:
Returns:
Type
any

remove() → {QueryWrapper}

Remove the set of matched nodes

Source:
Returns:
Type
QueryWrapper

replace(fn) → {QueryWrapper}

Replace each node in the set of matched nodes by returning a new node for each node that will be replaced

Parameters:
Name Type Description
fn function
Source:
Returns:
Type
QueryWrapper

value()

Get the combined string contents of each node in the set of matched nodes, including their descendants

Source: