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.
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.
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
undefined
if the attribute does not exist.
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
.
externalis
Checks the current list of elements and returns
true
if any of the elements match the selector. If using an element or Cheerio selection, returnstrue
if any of the elements match. If using a predicate function, the function is executed in the context of the selected element, sothis
refers 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.
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
value
is specified the instance itself, otherwise the prop's value.
externalremoveAttr
externalremoveClass
Removes one or more space-separated classes from the selected elements. If no
className
is 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.
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.
externalval
Method for getting the value of input, select, and textarea. Note: Support for
map
, andfunction
has not been added yet.Parameters
externalthis: Cheerio<T>
Returns string | undefined | string[]
The value.
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.
Forms
externalserialize
Encode a set of form elements as a string for submission.
Parameters
externalthis: Cheerio<T>
Returns string
The serialized form.
externalserializeArray
Encode a set of form elements as an array of names and values.
Parameters
externalthis: Cheerio<T>
Returns SerializedField[]
The serialized form.
Manipulation
externalafter
externalappend
externalappendTo
externalbefore
externalclone
externalempty
externalhtml
Gets an HTML content string from the first selected element.
Parameters
externalthis: Cheerio<T>
Returns string | null
The HTML content string.
externalinsertAfter
externalinsertBefore
externalprepend
externalprependTo
externalremove
externalreplaceWith
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.
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.
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>
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.
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.
Traversing
externaladd
externaladdBack
externalchildren
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.
externalcontents
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
this
refers to the current element, which is equivalent to the function parameterelement
. To break out of theeach
loop 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.
externalend
externaleq
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
this
refers 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.
externalfind
externalfirst
externalget
Retrieve one of the elements matched by the Cheerio object, at the
i
th position.Parameters
externalthis: Cheerio<T>
externali: number
Element to retrieve.
Returns T | undefined
The element at the
i
th position.
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.
externalindex
externallast
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.
externalnext
externalnextAll
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.
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 returnstrue
are 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.
externalparent
externalparents
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.
externalprev
externalprevAll
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.
externalsiblings
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.
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.
Adds class(es) to all of the matched elements. Also accepts a
function
.https://api.jquery.com/addClass/