Instance of cheerio. Methods are specified in the modules. Usage of this
constructor is not recommended. Please use $.load
instead.
The new selection.
Sets the root node.
Options for the instance.
The root of the document. Can be set by using the root
argument of the constructor.
Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.
The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.
The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.
Inserts content as the last child of each of the selected elements.
Inserts content as the first child of each of the selected elements.
The .wrap() function can take any string or object that could be passed to the $() factory function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. A copy of this structure will be wrapped around each of the elements in the set of matched elements. This method returns the original set of elements for chaining purposes.
The DOM structure to wrap around each element in the selection.
The .wrapInner() function can take any string or object that could be passed to the $() factory function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. The structure will be wrapped around the content of each of the elements in the set of matched elements.
The DOM structure to wrap around the content of each element in the selection.
The instance itself, for chaining.
Gets all the following siblings up to but not including the element matched by the selector, optionally filtered by another selector.
Selector for element to stop at.
If specified filter for siblings.
The next nodes.
Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector, DOM node, or cheerio object.
Selector for element to stop at.
Optional filter for parents.
The parents.
Gets all the preceding siblings up to but not including the element matched by the selector, optionally filtered by another selector.
Selector for element to stop at.
If specified filter for siblings.
The previous nodes.
Method for getting attributes. Gets the attribute value for only the first element in the matched set.
Name of the attribute.
The attribute's value.
Method for getting all attributes and their values of the first element in the matched set.
The attribute's values.
Method for setting attributes. Sets the attribute value for only the first
element in the matched set. If you set an attribute's value to null
, you
remove that attribute. You may also pass a map
and function
.
Name of the attribute.
The new value of the attribute.
The instance itself.
Method for setting multiple attributes at once. Sets the attribute value for
only the first element in the matched set. If you set an attribute's value to
null
, you remove that attribute.
Map of attribute names and values.
The instance itself.
Method for getting data attributes, for only the first element in the matched set.
Name of the data attribute.
The data attribute's value, or undefined
if the attribute does not exist.
Method for getting all of an element's data attributes, for only the first element in the matched set.
A map with all of the data attributes.
Method for setting data attributes, for only the first element in the matched set.
Name of the data attribute.
The new value.
The instance itself.
Method for setting multiple data attributes at once, for only the first element in the matched set.
Map of names to values.
The instance itself.
Checks the current list of elements and returns true
if any of the
elements match the selector. If using an element or Cheerio selection,
returns true
if any of the elements match. If using a predicate function,
the function is executed in the context of the selected element, so this
refers to the current element.
Selector for the selection.
Whether or not the selector matches an element of the instance.
Method for getting and setting properties. Gets the property value for only the first element in the matched set.
Name of the property.
If value
is specified the instance itself, otherwise the prop's value.
Get a parsed CSS style object.
Resolve href
or src
of supported elements. Requires the baseURI
option
to be set, and a global URL
object to be part of the environment.
Get a property of an element.
Set a property of an element.
Removes one or more space-separated classes from the selected elements. If no
className
is defined, all classes will be removed. Also accepts a function
.
Name of the class. If not specified, removes all elements.
The instance itself.
Add or remove class(es) from the matched elements, depending on either the
class's presence or the value of the switch argument. Also accepts a function
.
Name of the class. Can also be a function.
If specified the state of the class.
The instance itself.
Method for getting the value of input, select, and textarea. Note: Support
for map
, and function
has not been added yet.
The value.
Method for setting the value of input, select, and textarea. Note: Support
for map
, and function
has not been added yet.
The new value.
The instance itself.
Get the value of a style property for the first element in the set of matched elements.
Optionally the names of the properties of interest.
A map of all of the style properties.
Get the value of a style property for the first element in the set of matched elements.
The property value for the given name.
Set one CSS property for every matched element.
The name of the property.
The new value.
The instance itself.
Set multiple CSS properties for every matched element.
A map of property names and values.
The instance itself.
Create an array of nodes, recursing into arrays and parsing strings if necessary.
Elements to make an array of.
Optionally clone nodes.
The array of nodes.
Insert content next to each element in the set of matched elements.
The instance itself.
Insert every element in the set of matched elements to the end of the target.
Element to append elements to.
The instance itself.
Insert content previous to each element in the set of matched elements.
The instance itself.
Gets an HTML content string from the first selected element.
The HTML content string.
Replaces each selected element's content with the specified content.
The instance itself.
Insert every element in the set of matched elements after the target.
Element to insert elements after.
The set of newly inserted elements.
Insert every element in the set of matched elements before the target.
Element to insert elements before.
The set of newly inserted elements.
Insert every element in the set of matched elements to the beginning of the target.
Element to prepend elements to.
The instance itself.
Replaces matched elements with content
.
Replacement for matched elements.
The instance itself.
Get the combined text contents of each element in the set of matched elements, including their descendants.
The text contents of the collection.
Set the content of each element in the set of matched elements to the specified text.
The text to set as the content of each matched element.
The instance itself.
The .unwrap() function, removes the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
A selector to check the parent element against. If an element's parent does not match the selector, the element won't be unwrapped.
The instance itself, for chaining.
The .wrapAll() function can take any string or object that could be passed to the $() function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. The structure will be wrapped around all of the elements in the set of matched elements, as a single group.
The DOM structure to wrap around all matched elements in the selection.
The instance itself.
Make a cheerio object.
The contents of the new object.
The context of the new object.
The new cheerio object.
Parses some content.
Content to parse.
Options for parsing.
Allows parser to be switched to fragment mode.
A document containing the content
.
Retrieve all the DOM elements contained in the jQuery set as an array.
The contained items.
For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
Selector for the element to find.
The closest nodes.
Iterates over a cheerio object, executing a function for each matched
element. When the callback is fired, the function is fired in the context of
the DOM element, so this
refers to the current element, which is equivalent
to the function parameter element
. To break out of the each
loop early,
return with false
.
Function to execute.
The instance itself, useful for chaining.
Iterates over a cheerio object, reducing the set of selector elements to those that match the selector or pass the function's test.
This is the definition for using type guards; have a look below for other
ways to invoke this method. The function is executed in the context of the
selected element, so this
refers to the current element.
Value to look for, following the rules above.
The filtered collection.
Iterates over a cheerio object, reducing the set of selector elements to those that match the selector or pass the function's test.
this
refers to the current element.Value to look for, following the rules above. See AcceptedFilters.
The filtered collection.
Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
Element to look for.
The found elements.
Retrieve one of the elements matched by the Cheerio object, at the i
th position.
Element to retrieve.
The element at the i
th position.
Retrieve all elements matched by the Cheerio object, as an array.
All elements matched by the Cheerio object.
Pass each element in the current matched set through a function, producing a new Cheerio object containing the return values. The function can return an individual data item or an array of data items to be inserted into the resulting set. If an array is returned, the elements inside the array are inserted into the set. If the function returns null or undefined, no element will be inserted.
Function to execute.
The mapped elements, wrapped in a Cheerio collection.
Remove elements from the set of matched elements. Given a Cheerio object that
represents a set of DOM elements, the .not()
method constructs a new
Cheerio object from a subset of the matching elements. The supplied selector
is tested against each element; the elements that don't match the selector
will be included in the result.
The .not()
method can take a function as its argument in the same way that
.filter()
does. Elements for which the function returns true
are excluded
from the filtered set; all other elements are included.
Value to look for, following the rules above.
The filtered collection.
Gets the elements matching the specified range (0-based position).
An position at which the elements begin to be selected. If negative, it indicates an offset from the end of the set.
An position at which the elements stop being selected. If negative, it indicates an offset from the end of the set. If omitted, the range continues until the end of the set.
The elements matching the specified range.
The main types of Cheerio objects.