This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document.
selector searches within the context scope, which searches within the
root scope.
Optionalselector: S | BasicAcceptedElems<T>Either a selector to look for within the document, or the contents of a new Cheerio instance.
Optionalcontext: BasicAcceptedElems<AnyNode>Either a selector to look for within the root, or the contents of the document to query.
Optionalroot: BasicAcceptedElems<Document>Optional HTML document string.
Optionaloptions: CheerioOptions$('ul .pear').attr('class');
//=> pear
$('li[class=orange]').html();
//=> Orange
$('.apple', '#fruits').text();
//=> Apple
Optionally, you can also load HTML by passing the string as the selector:
$('<ul id="fruits">...</ul>');
Or the context:
$('ul', '<ul id="fruits">...</ul>');
Or as the root:
$('li', 'ul', '<ul id="fruits">...</ul>');
The .load static method defined on the "loaded" Cheerio factory function
is deprecated. Users are encouraged to instead use the load function
exported by the Cheerio module.
Checks to see if the contained DOM element is a descendant of the
container DOM element.
Indicates if the nodes contain one another.
Extract multiple values from a document, and store them in an object.
An object containing key-value pairs. The keys are the names of the properties to be created on the object, and the values are the selectors to be used to extract the values.
An object containing the extracted values.
Renders the document.
Optionaloptions: CheerioOptionsOptions for the renderer.
The rendered document.
Renders the document.
Optionaldom: BasicAcceptedElems<AnyNode>Element to render.
Optionaloptions: CheerioOptionsOptions for the renderer.
The rendered document.
Parses a string into an array of DOM nodes. The context argument has no
meaning for Cheerio, but it is maintained for API compatibility with jQuery.
Markup that will be parsed.
Optionalcontext: unknownWill be ignored. If it is a boolean it will be used as the
value of keepScripts.
OptionalkeepScripts: booleanIf false all scripts will be removed.
The parsed DOM.
Parses a string into an array of DOM nodes. The context argument has no
meaning for Cheerio, but it is maintained for API compatibility with jQuery.
Optionaldata: ""Markup that will be parsed.
The parsed DOM.
Sometimes you need to work with the top-level root element. To query it, you
can use $.root().
Cheerio instance wrapping the root node.
Render the document as text.
This returns the textContent of the passed elements. The result will
include the contents of <script> and <style> elements. To avoid this, use
.prop('innerText') instead.
Optionalelements: ArrayLike<AnyNode>Elements to render.
The rendered document.
Render the document as XML.
Optionaldom: BasicAcceptedElems<AnyNode>Element to render.
THe rendered document.
A querying function, bound to a document created from the provided markup.
Also provides several helper methods for dealing with the document as a whole.