externalabstractCheerio <T>
Hierarchy
- AttributesType
- TraversingType
- ManipulationType
- CssType
- FormsType
- Iterable<T>
- Cheerio
Implements
- ArrayLike<T>
Index
Attributes
CSS
Forms
Manipulation
Traversing
Other
Attributes
externaladdClass
Parameters
externalthis: R
externaloptionalvalue: string | (this, i, className) => undefined | string
Name of new class.
Returns R
The instance itself.
$('.pear').addClass('fruit').html();//=> <li class="pear fruit">Pear</li>$('.apple').addClass('fruit red').html();//=> <li class="apple fruit red">Apple</li>See more at https://api.jquery.com/addClass/
externalattr
Method for getting attributes. Gets the attribute value for only the first element in the matched set.
Parameters
externalthis: Cheerio<T>
externalname: string
Name of the attribute.
Returns string | undefined
The attribute's value.
$('ul').attr('id');//=> fruitsSee more at https://api.jquery.com/attr/
externaldata
Method for getting data attributes, for only the first element in the matched set.
Parameters
externalthis: Cheerio<T>
externalname: string
Name of the data attribute.
Returns unknown | undefined
The data attribute's value, or
undefinedif the attribute does not exist.$('<div data-apple-color="red"></div>').data('apple-color');//=> 'red'See more at https://api.jquery.com/data/
externalhasClass
Check to see if any of the matched elements have the given
className.Parameters
externalthis: Cheerio<T>
externalclassName: string
Name of the class.
Returns boolean
Indicates if an element has the given
className.$('.pear').hasClass('pear');//=> true$('apple').hasClass('fruit');//=> false$('li').hasClass('pear');//=> trueSee more at https://api.jquery.com/hasClass/
externalis
Checks the current list of elements and returns
trueif any of the elements match the selector. If using an element or Cheerio selection, returnstrueif any of the elements match. If using a predicate function, the function is executed in the context of the selected element, sothisrefers to the current element.Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<T>
Selector for the selection.
Returns boolean
Whether or not the selector matches an element of the instance.
See more at https://api.jquery.com/is/
externalprop
Method for getting and setting properties. Gets the property value for only the first element in the matched set.
Parameters
externalthis: Cheerio<T>
externalname: tagName | nodeName
Name of the property.
Returns T extends Element ? string : undefined
If
valueis specified the instance itself, otherwise the prop's value.$('input[type="checkbox"]').prop('checked');//=> false$('input[type="checkbox"]').prop('checked', true).val();//=> okSee more at https://api.jquery.com/prop/
externalremoveAttr
Method for removing attributes by
name.Parameters
externalthis: Cheerio<T>
externalname: string
Name of the attribute.
Returns Cheerio<T>
The instance itself.
$('.pear').removeAttr('class').html();//=> <li>Pear</li>$('.apple').attr('id', 'favorite');$('.apple').removeAttr('id class').html();//=> <li>Apple</li>See more at https://api.jquery.com/removeAttr/
externalremoveClass
Removes one or more space-separated classes from the selected elements. If no
classNameis defined, all classes will be removed. Also accepts afunction.Parameters
externalthis: R
externaloptionalname: string | (this, i, className) => undefined | string
Name of the class. If not specified, removes all elements.
Returns R
The instance itself.
$('.pear').removeClass('pear').html();//=> <li class="">Pear</li>$('.apple').addClass('red').removeClass().html();//=> <li class="">Apple</li>See more at https://api.jquery.com/removeClass/
externaltoggleClass
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.Parameters
externalthis: R
externaloptionalvalue: string | (this, i, className, stateVal) => string
Name of the class. Can also be a function.
externaloptionalstateVal: boolean
If specified the state of the class.
Returns R
The instance itself.
$('.apple.green').toggleClass('fruit green red').html();//=> <li class="apple fruit red">Apple</li>$('.apple.green').toggleClass('fruit green red', true).html();//=> <li class="apple green fruit red">Apple</li>See more at https://api.jquery.com/toggleClass/
externalval
Method for getting the value of input, select, and textarea. Note: Support for
map, andfunctionhas not been added yet.Parameters
externalthis: Cheerio<T>
Returns string | undefined | string[]
The value.
$('input[type="text"]').val();//=> input_textSee more at https://api.jquery.com/val/
CSS
externalcss
Get the value of a style property for the first element in the set of matched elements.
Parameters
externalthis: Cheerio<T>
externaloptionalnames: string[]
Optionally the names of the properties of interest.
Returns Record<string, string> | undefined
A map of all of the style properties.
See more at https://api.jquery.com/css/
Forms
externalserialize
Encode a set of form elements as a string for submission.
Parameters
externalthis: Cheerio<T>
Returns string
The serialized form.
$('<form><input name="foo" value="bar" /></form>').serialize();//=> 'foo=bar'See more at https://api.jquery.com/serialize/
externalserializeArray
Encode a set of form elements as an array of names and values.
Parameters
externalthis: Cheerio<T>
Returns SerializedField[]
The serialized form.
$('<form><input name="foo" value="bar" /></form>').serializeArray();//=> [ { name: 'foo', value: 'bar' } ]See more at https://api.jquery.com/serializeArray/
Manipulation
externalafter
Insert content next to each element in the set of matched elements.
Parameters
externalthis: Cheerio<T>
externalrest...elems: [(this, i, html) => BasicAcceptedElems<AnyNode>] | BasicAcceptedElems<AnyNode>[]
Returns Cheerio<T>
The instance itself.
$('.apple').after('<li class="plum">Plum</li>');$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="plum">Plum</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/after/
externalappend
Inserts content as the last child of each of the selected elements.
Parameters
externalthis: Cheerio<T>
externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]
Returns Cheerio<T>
$('ul').append('<li class="plum">Plum</li>');$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// <li class="plum">Plum</li>// </ul>See more at https://api.jquery.com/append/
externalappendTo
Insert every element in the set of matched elements to the end of the target.
Parameters
externalthis: Cheerio<T>
externaltarget: BasicAcceptedElems<AnyNode>
Element to append elements to.
Returns Cheerio<T>
The instance itself.
$('<li class="plum">Plum</li>').appendTo('#fruits');$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// <li class="plum">Plum</li>// </ul>See more at https://api.jquery.com/appendTo/
externalbefore
Insert content previous to each element in the set of matched elements.
Parameters
externalthis: Cheerio<T>
externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]
Returns Cheerio<T>
The instance itself.
$('.apple').before('<li class="plum">Plum</li>');$.html();//=> <ul id="fruits">// <li class="plum">Plum</li>// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/before/
externalclone
Clone the cheerio object.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<T>
The cloned object.
const moreFruit = $('#fruits').clone();See more at https://api.jquery.com/clone/
externalempty
Empties an element, removing all its children.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<T>
The instance itself.
$('ul').empty();$.html();//=> <ul id="fruits"></ul>See more at https://api.jquery.com/empty/
externalhtml
Gets an HTML content string from the first selected element.
Parameters
externalthis: Cheerio<T>
Returns string | null
The HTML content string.
$('.orange').html();//=> Orange$('#fruits').html('<li class="mango">Mango</li>').html();//=> <li class="mango">Mango</li>See more at https://api.jquery.com/html/
externalinsertAfter
Insert every element in the set of matched elements after the target.
Parameters
externalthis: Cheerio<T>
externaltarget: BasicAcceptedElems<AnyNode>
Element to insert elements after.
Returns Cheerio<T>
The set of newly inserted elements.
$('<li class="plum">Plum</li>').insertAfter('.apple');$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="plum">Plum</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/insertAfter/
externalinsertBefore
Insert every element in the set of matched elements before the target.
Parameters
externalthis: Cheerio<T>
externaltarget: BasicAcceptedElems<AnyNode>
Element to insert elements before.
Returns Cheerio<T>
The set of newly inserted elements.
$('<li class="plum">Plum</li>').insertBefore('.apple');$.html();//=> <ul id="fruits">// <li class="plum">Plum</li>// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/insertBefore/
externalprepend
Inserts content as the first child of each of the selected elements.
Parameters
externalthis: Cheerio<T>
externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]
Returns Cheerio<T>
$('ul').prepend('<li class="plum">Plum</li>');$.html();//=> <ul id="fruits">// <li class="plum">Plum</li>// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/prepend/
externalprependTo
Insert every element in the set of matched elements to the beginning of the target.
Parameters
externalthis: Cheerio<T>
externaltarget: BasicAcceptedElems<AnyNode>
Element to prepend elements to.
Returns Cheerio<T>
The instance itself.
$('<li class="plum">Plum</li>').prependTo('#fruits');$.html();//=> <ul id="fruits">// <li class="plum">Plum</li>// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>See more at https://api.jquery.com/prependTo/
externalremove
Removes the set of matched elements from the DOM and all their children.
selectorfilters the set of matched elements to be removed.Parameters
externalthis: Cheerio<T>
externaloptionalselector: string
Optional selector for elements to remove.
Returns Cheerio<T>
The instance itself.
$('.pear').remove();$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="orange">Orange</li>// </ul>See more at https://api.jquery.com/remove/
externalreplaceWith
Replaces matched elements with
content.Parameters
externalthis: Cheerio<T>
externalcontent: AcceptedElems<AnyNode>
Replacement for matched elements.
Returns Cheerio<T>
The instance itself.
const plum = $('<li class="plum">Plum</li>');$('.pear').replaceWith(plum);$.html();//=> <ul id="fruits">// <li class="apple">Apple</li>// <li class="orange">Orange</li>// <li class="plum">Plum</li>// </ul>See more at https://api.jquery.com/replaceWith/
externaltext
Get the combined text contents of each element in the set of matched elements, including their descendants.
Parameters
externalthis: Cheerio<T>
Returns string
The text contents of the collection.
$('.orange').text();//=> Orange$('ul').text();//=> Apple// Orange// PearSee more at https://api.jquery.com/text/
externaltoString
Turns the collection to a string. Alias for
.html().Parameters
externalthis: Cheerio<T>
Returns string
The rendered document.
externalunwrap
The .unwrap() function, removes the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: string
A selector to check the parent element against. If an element's parent does not match the selector, the element won't be unwrapped.
Returns Cheerio<T>
The instance itself, for chaining.
const $ = cheerio.load('<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>');$('#test p').unwrap();//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div>const $ = cheerio.load('<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>');$('#test p').unwrap('b');//=> <div id=test>// <p>Hello</p>// <p>World</p>// </div>See more at https://api.jquery.com/unwrap/
externalwrap
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.
Parameters
externalthis: Cheerio<T>
externalwrapper: AcceptedElems<AnyNode>
The DOM structure to wrap around each element in the selection.
Returns Cheerio<T>
const redFruit = $('<div class="red-fruit"></div>');$('.apple').wrap(redFruit);//=> <ul id="fruits">// <div class="red-fruit">// <li class="apple">Apple</li>// </div>// <li class="orange">Orange</li>// <li class="plum">Plum</li>// </ul>const healthy = $('<div class="healthy"></div>');$('li').wrap(healthy);//=> <ul id="fruits">// <div class="healthy">// <li class="apple">Apple</li>// </div>// <div class="healthy">// <li class="orange">Orange</li>// </div>// <div class="healthy">// <li class="plum">Plum</li>// </div>// </ul>See more at https://api.jquery.com/wrap/
externalwrapAll
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.
Parameters
externalthis: Cheerio<T>
externalwrapper: AcceptedElems<T>
The DOM structure to wrap around all matched elements in the selection.
Returns Cheerio<T>
The instance itself.
const $ = cheerio.load('<div class="container"><div class="inner">First</div><div class="inner">Second</div></div>');$('.inner').wrapAll("<div class='new'></div>");//=> <div class="container">// <div class='new'>// <div class="inner">First</div>// <div class="inner">Second</div>// </div>// </div>const $ = cheerio.load('<span>Span 1</span><strong>Strong</strong><span>Span 2</span>');const wrap = $('<div><p><em><b></b></em></p></div>');$('span').wrapAll(wrap);//=> <div>// <p>// <em>// <b>// <span>Span 1</span>// <span>Span 2</span>// </b>// </em>// </p>// </div>// <strong>Strong</strong>See more at https://api.jquery.com/wrapAll/
externalwrapInner
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.
Parameters
externalthis: Cheerio<T>
externalwrapper: AcceptedElems<AnyNode>
The DOM structure to wrap around the content of each element in the selection.
Returns Cheerio<T>
The instance itself, for chaining.
const redFruit = $('<div class="red-fruit"></div>');$('.apple').wrapInner(redFruit);//=> <ul id="fruits">// <li class="apple">// <div class="red-fruit">Apple</div>// </li>// <li class="orange">Orange</li>// <li class="pear">Pear</li>// </ul>const healthy = $('<div class="healthy"></div>');$('li').wrapInner(healthy);//=> <ul id="fruits">// <li class="apple">// <div class="healthy">Apple</div>// </li>// <li class="orange">// <div class="healthy">Orange</div>// </li>// <li class="pear">// <div class="healthy">Pear</div>// </li>// </ul>See more at https://api.jquery.com/wrapInner/
Traversing
externaladd
Add elements to the set of matched elements.
Parameters
externalthis: Cheerio<T>
externalother: string | S | Cheerio<S> | S[]
Elements to add.
externaloptionalcontext: string | Cheerio<S>
Optionally the context of the new selection.
Returns Cheerio<S | T>
The combined set.
$('.apple').add('.orange').length;//=> 2See more at https://api.jquery.com/add/
externaladdBack
Add the previous set of elements on the stack to the current set, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: string
Selector for the elements to add.
Returns Cheerio<AnyNode>
The combined set.
$('li').eq(0).addBack('.orange').length;//=> 2See more at https://api.jquery.com/addBack/
externalchildren
Gets the element children of each element in the set of matched elements.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for children.
Returns Cheerio<Element>
The children.
$('#fruits').children().length;//=> 3$('#fruits').children('.pear').text();//=> PearSee more at https://api.jquery.com/children/
externalclosest
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.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
Selector for the element to find.
Returns Cheerio<AnyNode>
The closest nodes.
$('.orange').closest();//=> []$('.orange').closest('.apple');// => []$('.orange').closest('li');//=> [<li class="orange">Orange</li>]$('.orange').closest('#fruits');//=> [<ul id="fruits"> ... </ul>]See more at https://api.jquery.com/closest/
externalcontents
Gets the children of each element in the set of matched elements, including text and comment nodes.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<AnyNode>
The children.
$('#fruits').contents().length;//=> 3See more at https://api.jquery.com/contents/
externaleach
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
thisrefers to the current element, which is equivalent to the function parameterelement. To break out of theeachloop early, return withfalse.Parameters
externalthis: Cheerio<T>
externalfn: (this, i, el) => boolean | void
Function to execute.
Returns Cheerio<T>
The instance itself, useful for chaining.
const fruits = [];$('li').each(function (i, elem) {fruits[i] = $(this).text();});fruits.join(', ');//=> Apple, Orange, PearSee more at https://api.jquery.com/each/
externalend
End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<AnyNode>
The previous state of the set of matched elements.
$('li').eq(0).end().length;//=> 3See more at https://api.jquery.com/end/
externaleq
Reduce the set of matched elements to the one at the specified index. Use
.eq(-i)to count backwards from the last selected element.Parameters
externalthis: Cheerio<T>
externali: number
Index of the element to select.
Returns Cheerio<T>
The element at the
ith position.$('li').eq(0).text();//=> Apple$('li').eq(-1).text();//=> PearSee more at https://api.jquery.com/eq/
externalfilter
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
thisrefers to the current element.Parameters
externalthis: Cheerio<T>
externalmatch: (this, index, value) => value is S
Value to look for, following the rules above.
Returns Cheerio<S>
The filtered collection.
$('li').filter(function (i, el) {// this === elreturn $(this).attr('class') === 'orange';}).attr('class'); //=> orangeSee more at https://api.jquery.com/filter/
externalfind
Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
Parameters
externalthis: Cheerio<T>
externaloptionalselectorOrHaystack: string | Element | Cheerio<Element>
Element to look for.
Returns Cheerio<Element>
The found elements.
$('#fruits').find('li').length;//=> 3$('#fruits').find($('.apple')).length;//=> 1See more at https://api.jquery.com/find/
externalfirst
Will select the first element of a cheerio object.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<T>
The first element.
$('#fruits').children().first().text();//=> AppleSee more at https://api.jquery.com/first/
externalget
Retrieve one of the elements matched by the Cheerio object, at the
ith position.Parameters
externalthis: Cheerio<T>
externali: number
Element to retrieve.
Returns T | undefined
The element at the
ith position.$('li').get(0).tagName;//=> liSee more at https://api.jquery.com/get/
externalhas
Filters the set of matched elements to only those which have the given DOM element as a descendant or which have a descendant that matches the given selector. Equivalent to
.filter(':has(selector)').Parameters
externalthis: Cheerio<AnyNode>
externalselectorOrHaystack: string | Element | Cheerio<Element>
Element to look for.
Returns Cheerio<AnyNode | Element>
The filtered collection.
$('ul').has('.pear').attr('id');//=> fruits$('ul').has($('.pear')[0]).attr('id');//=> fruitsSee more at https://api.jquery.com/has/
externalindex
Search for a given element from among the matched elements.
Parameters
externalthis: Cheerio<T>
externaloptionalselectorOrNeedle: string | AnyNode | Cheerio<AnyNode>
Element to look for.
Returns number
The index of the element.
$('.pear').index();//=> 2 $('.orange').index('li');//=> 1$('.apple').index($('#fruit, li'));//=> 1See more at https://api.jquery.com/index/
externallast
Will select the last element of a cheerio object.
Parameters
externalthis: Cheerio<T>
Returns Cheerio<T>
The last element.
$('#fruits').children().last().text();//=> PearSee more at https://api.jquery.com/last/
externalmap
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.
Parameters
externalthis: Cheerio<T>
externalfn: (this, i, el) => undefined | null | M | M[]
Function to execute.
Returns Cheerio<M>
The mapped elements, wrapped in a Cheerio collection.
$('li').map(function (i, el) {// this === elreturn $(this).text();}).toArray().join(' ');//=> "apple orange pear"See more at https://api.jquery.com/map/
externalnext
Gets the next sibling of the first selected element, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for sibling.
Returns Cheerio<Element>
The next nodes.
$('.apple').next().hasClass('orange');//=> trueSee more at https://api.jquery.com/next/
externalnextAll
Gets all the following siblings of the first selected element, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The next nodes.
$('.apple').nextAll();//=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>]$('.apple').nextAll('.orange');//=> [<li class="orange">Orange</li>]See more at https://api.jquery.com/nextAll/
externalnextUntil
Gets all the following siblings up to but not including the element matched by the selector, optionally filtered by another selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: null | AcceptedFilters<Element>
Selector for element to stop at.
externaloptionalfilterSelector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The next nodes.
$('.apple').nextUntil('.pear');//=> [<li class="orange">Orange</li>]See more at https://api.jquery.com/nextUntil/
externalnot
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 returnstrueare excluded from the filtered set; all other elements are included.Parameters
externalthis: Cheerio<T>
externalmatch: AcceptedFilters<T>
Value to look for, following the rules above.
Returns Cheerio<T>
The filtered collection.
$('li').not('.apple').length;//=> 2$('li').not(function (i, el) {// this === elreturn $(this).attr('class') === 'orange';}).length; //=> 2See more at https://api.jquery.com/not/
externalparent
Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for parent.
Returns Cheerio<Element>
The parents.
$('.pear').parent().attr('id');//=> fruitsSee more at https://api.jquery.com/parent/
externalparents
Get a set of parents filtered by
selectorof each element in the current set of match elements.Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for parents.
Returns Cheerio<Element>
The parents.
$('.orange').parents().length;//=> 2$('.orange').parents('#fruits').length;//=> 1See more at https://api.jquery.com/parents/
externalparentsUntil
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.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: null | AcceptedFilters<Element>
Selector for element to stop at.
externaloptionalfilterSelector: AcceptedFilters<Element>
Optional filter for parents.
Returns Cheerio<Element>
The parents.
$('.orange').parentsUntil('#food').length;//=> 1See more at https://api.jquery.com/parentsUntil/
externalprev
Gets the previous sibling of the first selected element optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The previous nodes.
$('.orange').prev().hasClass('apple');//=> trueSee more at https://api.jquery.com/prev/
externalprevAll
Gets all the preceding siblings of the first selected element, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The previous nodes.
$('.pear').prevAll();//=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>]$('.pear').prevAll('.orange');//=> [<li class="orange">Orange</li>]See more at https://api.jquery.com/prevAll/
externalprevUntil
Gets all the preceding siblings up to but not including the element matched by the selector, optionally filtered by another selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: null | AcceptedFilters<Element>
Selector for element to stop at.
externaloptionalfilterSelector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The previous nodes.
$('.pear').prevUntil('.apple');//=> [<li class="orange">Orange</li>]See more at https://api.jquery.com/prevUntil/
externalsiblings
Get the siblings of each element (excluding the element) in the set of matched elements, optionally filtered by a selector.
Parameters
externalthis: Cheerio<T>
externaloptionalselector: AcceptedFilters<Element>
If specified filter for siblings.
Returns Cheerio<Element>
The siblings.
$('.pear').siblings().length;//=> 2$('.pear').siblings('.orange').length;//=> 1See more at https://api.jquery.com/siblings/
externalslice
Gets the elements matching the specified range (0-based position).
Parameters
externalthis: Cheerio<T>
externaloptionalstart: number
A position at which the elements begin to be selected. If negative, it indicates an offset from the end of the set.
externaloptionalend: number
A 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.
Returns Cheerio<T>
The elements matching the specified range.
$('li').slice(1).eq(0).text();//=> 'Orange'$('li').slice(1, 2).length;//=> 1See more at https://api.jquery.com/slice/
Other
externalcheerio
externallength
externaloptions
externalprevObject
externalsplice
Type declaration
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.
Parameters
externaloptionalstart: number
The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.
externaloptionalend: number
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.
Returns any[]
external[iterator]
Returns Iterator<T, any, any>
externalfilterArray
Parameters
externalnodes: T[]
externalmatch: AcceptedFilters<T>
externaloptionalxmlMode: boolean
externaloptionalroot: Document
Returns Element[] | T[]
externaltoArray
Retrieve all the DOM elements contained in the jQuery set as an array.
Parameters
externalthis: Cheerio<T>
Returns T[]
The contained items.
$('li').toArray();//=> [ {...}, {...}, {...} ]
Adds class(es) to all of the matched elements. Also accepts a
function.