Constructor
new QueryWrapper(nodes)
Create a new QueryWrapper
Parameters:
Name | Type | Description |
---|---|---|
nodes |
Array.<NodeWrapper> |
Methods
after(node) → {QueryWrapper}
Insert a node after each node in the set of matched nodes
Parameters:
Name | Type | Description |
---|---|---|
node |
object |
Returns:
- Type
- QueryWrapper
before(node) → {QueryWrapper}
Insert a node before each node in the set of matched nodes
Parameters:
Name | Type | Description |
---|---|---|
node |
object |
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> |
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> |
Returns:
- Type
- QueryWrapper
concat(wrapper) → {any}
Combine the nodes of two QueryWrappers
Parameters:
Name | Type | Description |
---|---|---|
wrapper |
QueryWrapper |
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 |
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> |
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> |
Returns:
- Type
- QueryWrapper
first() → {QueryWrapper}
Reduce the set of matched nodes to the first in the set.
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> |
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> |
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> |
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> |
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> |
Returns:
- Type
- number
last() → {QueryWrapper}
Reduce the set of matched nodes to the final one in the set
Returns:
- Type
- QueryWrapper
length() → {number}
Return the number of nodes in the wrapper
Returns:
- Type
- number
map(fn) → {array}
Map the set of matched nodes
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
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> |
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> |
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> |
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> |
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> |
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> |
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> |
Returns:
- Type
- QueryWrapper
reduce(fn, acc) → {any}
Reduce the set of matched nodes
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | |
acc |
any |
Returns:
- Type
- any
remove() → {QueryWrapper}
Remove the set of matched nodes
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 |
Returns:
- Type
- QueryWrapper
value()
Get the combined string contents of each node in the set of matched nodes, including their descendants