Class: abstract
Cheerio<T>
The cheerio class is the central class of the library. It wraps a set of elements and provides an API for traversing, modifying, and interacting with the set.
Loading a document will return the Cheerio class bound to the root element of
the document. The class will be instantiated when querying the document (when
calling $('selector')
).
Example
<ul id="fruits">
<li class="apple">Apple</li>
<li class="orange">Orange</li>
<li class="pear">Pear</li>
</ul>
Extends
MethodsType
.Iterable
<T
>
Type Parameters
• T
Implements
ArrayLike
<T
>
Indexable
[index
: number
]: T
Attributes
addClass()
addClass<
T
,R
>(this
,value
?):R
Adds class(es) to all of the matched elements. Also accepts a function
.
Type Parameters
• T extends AnyNode
• R extends ArrayLike
<T
>
Parameters
this
R
value?
Name of new class.
string
| (this
, i
, className
) => undefined
| string
Returns
R
The instance itself.
Example
$('.pear').addClass('fruit').prop('outerHTML');
//=> <li class="pear fruit">Pear</li>
$('.apple').addClass('fruit red').prop('outerHTML');
//=> <li class="apple fruit red">Apple</li>
See
https://api.jquery.com/addClass/
Defined in
attr()
Call Signature
attr<
T
>(this
,name
):string
|undefined
Method for getting attributes. Gets the attribute value for only the first element in the matched set.
Type Parameters
• T extends AnyNode
Parameters
this
Cheerio
<T
>
name
string
Name of the attribute.
Returns
string
| undefined
The attribute's value.
Example
$('ul').attr('id');
//=> fruits
See
Defined in
Call Signature
attr<
T
>(this
):Record
<string
,string
> |undefined
Method for getting all attributes and their values of the first element in the matched set.
Type Parameters
• T extends AnyNode
Parameters
this
Cheerio
<T
>