Skip to main content
Version: Next

externalabstractCheerio <T>

Hierarchy

  • AttributesType
  • TraversingType
  • ManipulationType
  • CssType
  • FormsType
  • Iterable<T>
    • Cheerio

Implements

  • ArrayLike<T>

Index

Attributes

externaladdClass

  • addClass<T, R>(this, value): R
  • Adds class(es) to all of the matched elements. Also accepts a function.

    @example
    $('.pear').addClass('fruit').html();
    //=> <li class="pear fruit">Pear</li>

    $('.apple').addClass('fruit red').html();
    //=> <li class="apple fruit red">Apple</li>
    @see

    Parameters

    • externalthis: R
    • externaloptionalvalue: string | (this, i, className) => undefined | string

      Name of new class.

      Returns R

      The instance itself.

    externalattr

    • attr<T>(this, name): string | undefined
    • attr<T>(this): Record<string, string> | undefined
    • attr<T>(this, name, value): Cheerio<T>
    • attr<T>(this, values): Cheerio<T>
    • Method for getting attributes. Gets the attribute value for only the first element in the matched set.

      @example
      $('ul').attr('id');
      //=> fruits
      @see

      Parameters

      • externalthis: Cheerio<T>
      • externalname: string

        Name of the attribute.

      Returns string | undefined

      The attribute's value.

    externaldata

    • data<T>(this, name): unknown | undefined
    • data<T>(this): Record<string, unknown>
    • data<T>(this, name, value): Cheerio<T>
    • data<T>(this, values): Cheerio<T>
    • Method for getting data attributes, for only the first element in the matched set.

      @example
      $('<div data-apple-color="red"></div>').data('apple-color');
      //=> 'red'
      @see

      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

    • hasClass<T>(this, className): boolean
    • Check to see if any of the matched elements have the given className.

      @example
      $('.pear').hasClass('pear');
      //=> true

      $('apple').hasClass('fruit');
      //=> false

      $('li').hasClass('pear');
      //=> true
      @see

      Parameters

      • externalthis: Cheerio<T>
      • externalclassName: string

        Name of the class.

      Returns boolean

      Indicates if an element has the given className.

    externalis

    • is<T>(this, selector): boolean
    • 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.

      @see

      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

    • prop<T>(this, name): T extends Element ? string : undefined
    • prop<T>(this, name): string | null
    • prop<T>(this, name): StyleProp | undefined
    • prop<T>(this, name): string | undefined
    • prop<T, K>(this, name): Element[K]
    • prop<T, K>(this, name, value): Cheerio<T>
    • prop<T>(this, name): Cheerio<T>
    • prop<T>(this, name, value): Cheerio<T>
    • prop<T>(this, name): string
    • Method for getting and setting properties. Gets the property value for only the first element in the matched set.

      @example
      $('input[type="checkbox"]').prop('checked');
      //=> false

      $('input[type="checkbox"]').prop('checked', true).val();
      //=> ok
      @see

      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

    • removeAttr<T>(this, name): Cheerio<T>
    • Method for removing attributes by name.

      @example
      $('.pear').removeAttr('class').html();
      //=> <li>Pear</li>

      $('.apple').attr('id', 'favorite');
      $('.apple').removeAttr('id class').html();
      //=> <li>Apple</li>
      @see

      Parameters

      • externalthis: Cheerio<T>
      • externalname: string

        Name of the attribute.

      Returns Cheerio<T>

      The instance itself.

    externalremoveClass

    • removeClass<T, R>(this, name): R
    • 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.

      @example
      $('.pear').removeClass('pear').html();
      //=> <li class="">Pear</li>

      $('.apple').addClass('red').removeClass().html();
      //=> <li class="">Apple</li>
      @see

      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

      • toggleClass<T, R>(this, value, stateVal): R
      • 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.

        @example
        $('.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

        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

        • val<T>(this): string | undefined | string[]
        • val<T>(this, value): Cheerio<T>
        • Method for getting the value of input, select, and textarea. Note: Support for map, and function has not been added yet.

          @example
          $('input[type="text"]').val();
          //=> input_text
          @see

          Parameters

          Returns string | undefined | string[]

          The value.

        CSS

        externalcss

        • css<T>(this, names): Record<string, string> | undefined
        • css<T>(this, name): string | undefined
        • css<T>(this, prop, val): Cheerio<T>
        • css<T>(this, map): Cheerio<T>
        • Get the value of a style property for the first element in the set of matched elements.

          @see

          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

        • serialize<T>(this): string
        • Encode a set of form elements as a string for submission.

          @example
          $('<form><input name="foo" value="bar" /></form>').serialize();
          //=> 'foo=bar'
          @see

          Parameters

          Returns string

          The serialized form.

        externalserializeArray

        • serializeArray<T>(this): SerializedField[]
        • Encode a set of form elements as an array of names and values.

          @example
          $('<form><input name="foo" value="bar" /></form>').serializeArray();
          //=> [ { name: 'foo', value: 'bar' } ]
          @see

          Parameters

          Returns SerializedField[]

          The serialized form.

        Manipulation

        externalafter

        • after<T>(this, ...elems): Cheerio<T>
        • Insert content next to each element in the set of matched elements.

          @example
          $('.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

          Parameters

          • externalthis: Cheerio<T>
          • externalrest...elems: [(this, i, html) => BasicAcceptedElems<AnyNode>] | BasicAcceptedElems<AnyNode>[]

          Returns Cheerio<T>

          The instance itself.

        externalappend

        • append<T>(this, ...elems): Cheerio<T>
        • Inserts content as the last child of each of the selected elements.

          @example
          $('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

          Parameters

          • externalthis: Cheerio<T>
          • externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]

          Returns Cheerio<T>

        externalappendTo

        • appendTo<T>(this, target): Cheerio<T>
        • Insert every element in the set of matched elements to the end of the target.

          @example
          $('<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

          Parameters

          • externalthis: Cheerio<T>
          • externaltarget: BasicAcceptedElems<AnyNode>

            Element to append elements to.

          Returns Cheerio<T>

          The instance itself.

        externalbefore

        • before<T>(this, ...elems): Cheerio<T>
        • Insert content previous to each element in the set of matched elements.

          @example
          $('.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

          Parameters

          • externalthis: Cheerio<T>
          • externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]

          Returns Cheerio<T>

          The instance itself.

        externalclone

        externalempty

        externalhtml

        • html<T>(this): string | null
        • html<T>(this, str): Cheerio<T>
        • Gets an HTML content string from the first selected element.

          @example
          $('.orange').html();
          //=> Orange

          $('#fruits').html('<li class="mango">Mango</li>').html();
          //=> <li class="mango">Mango</li>
          @see

          Parameters

          Returns string | null

          The HTML content string.

        externalinsertAfter

        • insertAfter<T>(this, target): Cheerio<T>
        • Insert every element in the set of matched elements after the target.

          @example
          $('<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

          Parameters

          • externalthis: Cheerio<T>
          • externaltarget: BasicAcceptedElems<AnyNode>

            Element to insert elements after.

          Returns Cheerio<T>

          The set of newly inserted elements.

        externalinsertBefore

        • insertBefore<T>(this, target): Cheerio<T>
        • Insert every element in the set of matched elements before the target.

          @example
          $('<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

          Parameters

          • externalthis: Cheerio<T>
          • externaltarget: BasicAcceptedElems<AnyNode>

            Element to insert elements before.

          Returns Cheerio<T>

          The set of newly inserted elements.

        externalprepend

        • prepend<T>(this, ...elems): Cheerio<T>
        • Inserts content as the first child of each of the selected elements.

          @example
          $('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

          Parameters

          • externalthis: Cheerio<T>
          • externalrest...elems: BasicAcceptedElems<AnyNode>[] | [(this, i, html) => BasicAcceptedElems<AnyNode>]

          Returns Cheerio<T>

        externalprependTo

        • prependTo<T>(this, target): Cheerio<T>
        • Insert every element in the set of matched elements to the beginning of the target.

          @example
          $('<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

          Parameters

          • externalthis: Cheerio<T>
          • externaltarget: BasicAcceptedElems<AnyNode>

            Element to prepend elements to.

          Returns Cheerio<T>

          The instance itself.

        externalremove

        • remove<T>(this, selector): Cheerio<T>
        • Removes the set of matched elements from the DOM and all their children. selector filters the set of matched elements to be removed.

          @example
          $('.pear').remove();
          $.html();
          //=> <ul id="fruits">
          // <li class="apple">Apple</li>
          // <li class="orange">Orange</li>
          // </ul>
          @see

          Parameters

          • externalthis: Cheerio<T>
          • externaloptionalselector: string

            Optional selector for elements to remove.

          Returns Cheerio<T>

          The instance itself.

        externalreplaceWith

        • replaceWith<T>(this, content): Cheerio<T>
        • Replaces matched elements with content.

          @example
          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

          Parameters

          • externalthis: Cheerio<T>
          • externalcontent: AcceptedElems<AnyNode>

            Replacement for matched elements.

          Returns Cheerio<T>

          The instance itself.

        externaltext

        • text<T>(this): string
        • text<T>(this, str): Cheerio<T>
        • Get the combined text contents of each element in the set of matched elements, including their descendants.

          @example
          $('.orange').text();
          //=> Orange

          $('ul').text();
          //=> Apple
          // Orange
          // Pear
          @see

          Parameters

          Returns string

          The text contents of the collection.

        externaltoString

        • toString<T>(this): string
        • Turns the collection to a string. Alias for .html().


          Parameters

          Returns string

          The rendered document.

        externalunwrap

        • unwrap<T>(this, selector): Cheerio<T>
        • The .unwrap() function, removes the parents of the set of matched elements from the DOM, leaving the matched elements in their place.

          @example
          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>
          @example
          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

          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.

          @example
          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

          Parameters

          • externalthis: Cheerio<T>
          • externalwrapper: AcceptedElems<AnyNode>

            The DOM structure to wrap around each element in the selection.

          Returns Cheerio<T>

        externalwrapAll

        • wrapAll<T>(this, wrapper): Cheerio<T>
        • 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.

          @example
          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>
          @example
          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

          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

        • wrapInner<T>(this, wrapper): Cheerio<T>
        • 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.

          @example
          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

          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

        • add<S, T>(this, other, context): Cheerio<S | T>
        • Add elements to the set of matched elements.

          @example
          $('.apple').add('.orange').length;
          //=> 2
          @see

          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.

        externaladdBack

        • addBack<T>(this, selector): Cheerio<AnyNode>
        • Add the previous set of elements on the stack to the current set, optionally filtered by a selector.

          @example
          $('li').eq(0).addBack('.orange').length;
          //=> 2
          @see

          Parameters

          • externalthis: Cheerio<T>
          • externaloptionalselector: string

            Selector for the elements to add.

          Returns Cheerio<AnyNode>

          The combined set.

        externalchildren

        • Gets the element children of each element in the set of matched elements.

          @example
          $('#fruits').children().length;
          //=> 3

          $('#fruits').children('.pear').text();
          //=> Pear
          @see

          Parameters

          • externalthis: Cheerio<T>
          • externaloptionalselector: AcceptedFilters<Element>

            If specified filter for children.

          Returns Cheerio<Element>

          The children.

        externalclosest

        • closest<T>(this, selector): Cheerio<AnyNode>
        • 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.

          @example
          $('.orange').closest();
          //=> []

          $('.orange').closest('.apple');
          // => []

          $('.orange').closest('li');
          //=> [<li class="orange">Orange</li>]

          $('.orange').closest('#fruits');
          //=> [<ul id="fruits"> ... </ul>]
          @see

          Parameters

          • externalthis: Cheerio<T>
          • externaloptionalselector: AcceptedFilters<Element>

            Selector for the element to find.

          Returns Cheerio<AnyNode>

          The closest nodes.

        externalcontents

        • contents<T>(this): Cheerio<AnyNode>
        • Gets the children of each element in the set of matched elements, including text and comment nodes.

          @example
          $('#fruits').contents().length;
          //=> 3
          @see

          Parameters

          Returns Cheerio<AnyNode>

          The children.

        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 parameter element. To break out of the each loop early, return with false.

          @example
          const fruits = [];

          $('li').each(function (i, elem) {
          fruits[i] = $(this).text();
          });

          fruits.join(', ');
          //=> Apple, Orange, Pear
          @see

          Parameters

          • externalthis: Cheerio<T>
          • externalfn: (this, i, el) => boolean | void

            Function to execute.

            Returns Cheerio<T>

            The instance itself, useful for chaining.

          externalend

          • End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.

            @example
            $('li').eq(0).end().length;
            //=> 3
            @see

            Parameters

            Returns Cheerio<AnyNode>

            The previous state of the set of matched elements.

          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.

            @example
            $('li').eq(0).text();
            //=> Apple

            $('li').eq(-1).text();
            //=> Pear
            @see

            Parameters

            • externalthis: Cheerio<T>
            • externali: number

              Index of the element to select.

            Returns Cheerio<T>

            The element at the ith position.

          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.

            @example
            $('li')
            .filter(function (i, el) {
            // this === el
            return $(this).attr('class') === 'orange';
            })
            .attr('class'); //=> orange
            @see

            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

            • Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

              @example
              $('#fruits').find('li').length;
              //=> 3
              $('#fruits').find($('.apple')).length;
              //=> 1
              @see

              Parameters

              Returns Cheerio<Element>

              The found elements.

            externalfirst

            externalget

            • get<T>(this, i): T | undefined
            • get<T>(this): T[]
            • Retrieve one of the elements matched by the Cheerio object, at the ith position.

              @example
              $('li').get(0).tagName;
              //=> li
              @see

              Parameters

              • externalthis: Cheerio<T>
              • externali: number

                Element to retrieve.

              Returns T | undefined

              The element at the ith 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)').

              @example
              $('ul').has('.pear').attr('id');
              //=> fruits
              @example
              $('ul').has($('.pear')[0]).attr('id');
              //=> fruits
              @see

              Parameters

              Returns Cheerio<AnyNode | Element>

              The filtered collection.

            externalindex

            • index<T>(this, selectorOrNeedle): number
            • Search for a given element from among the matched elements.

              @example
              $('.pear').index();
              //=> 2 $('.orange').index('li');
              //=> 1
              $('.apple').index($('#fruit, li'));
              //=> 1
              @see

              Parameters

              • externalthis: Cheerio<T>
              • externaloptionalselectorOrNeedle: string | AnyNode | Cheerio<AnyNode>

                Element to look for.

              Returns number

              The index of the element.

            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.

              @example
              $('li')
              .map(function (i, el) {
              // this === el
              return $(this).text();
              })
              .toArray()
              .join(' ');
              //=> "apple orange pear"
              @see

              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

              • Gets the next sibling of the first selected element, optionally filtered by a selector.

                @example
                $('.apple').next().hasClass('orange');
                //=> true
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for sibling.

                Returns Cheerio<Element>

                The next nodes.

              externalnextAll

              • Gets all the following siblings of the first selected element, optionally filtered by a selector.

                @example
                $('.apple').nextAll();
                //=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>]
                $('.apple').nextAll('.orange');
                //=> [<li class="orange">Orange</li>]
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for siblings.

                Returns Cheerio<Element>

                The next nodes.

              externalnextUntil

              • Gets all the following siblings up to but not including the element matched by the selector, optionally filtered by another selector.

                @example
                $('.apple').nextUntil('.pear');
                //=> [<li class="orange">Orange</li>]
                @see

                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 returns true are excluded from the filtered set; all other elements are included.

                @example
                $('li').not('.apple').length;
                //=> 2
                @example
                $('li').not(function (i, el) {
                // this === el
                return $(this).attr('class') === 'orange';
                }).length; //=> 2
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externalmatch: AcceptedFilters<T>

                  Value to look for, following the rules above.

                Returns Cheerio<T>

                The filtered collection.

              externalparent

              • Get the parent of each element in the current set of matched elements, optionally filtered by a selector.

                @example
                $('.pear').parent().attr('id');
                //=> fruits
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for parent.

                Returns Cheerio<Element>

                The parents.

              externalparents

              • Get a set of parents filtered by selector of each element in the current set of match elements.

                @example
                $('.orange').parents().length;
                //=> 2
                $('.orange').parents('#fruits').length;
                //=> 1
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for parents.

                Returns Cheerio<Element>

                The 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.

                @example
                $('.orange').parentsUntil('#food').length;
                //=> 1
                @see

                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

              • Gets the previous sibling of the first selected element optionally filtered by a selector.

                @example
                $('.orange').prev().hasClass('apple');
                //=> true
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for siblings.

                Returns Cheerio<Element>

                The previous nodes.

              externalprevAll

              • Gets all the preceding siblings of the first selected element, optionally filtered by a selector.

                @example
                $('.pear').prevAll();
                //=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>]

                $('.pear').prevAll('.orange');
                //=> [<li class="orange">Orange</li>]
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for siblings.

                Returns Cheerio<Element>

                The previous nodes.

              externalprevUntil

              • Gets all the preceding siblings up to but not including the element matched by the selector, optionally filtered by another selector.

                @example
                $('.pear').prevUntil('.apple');
                //=> [<li class="orange">Orange</li>]
                @see

                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

              • Get the siblings of each element (excluding the element) in the set of matched elements, optionally filtered by a selector.

                @example
                $('.pear').siblings().length;
                //=> 2

                $('.pear').siblings('.orange').length;
                //=> 1
                @see

                Parameters

                • externalthis: Cheerio<T>
                • externaloptionalselector: AcceptedFilters<Element>

                  If specified filter for siblings.

                Returns Cheerio<Element>

                The siblings.

              externalslice

              • slice<T>(this, start, end): Cheerio<T>
              • Gets the elements matching the specified range (0-based position).

                @example
                $('li').slice(1).eq(0).text();
                //=> 'Orange'

                $('li').slice(1, 2).length;
                //=> 1
                @see

                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

              cheerio: [cheerio object]

              externallength

              length: number

              externaloptions

              options: InternalOptions

              externalprevObject

              prevObject: undefined | Cheerio<any>

              externalsplice

              splice: (start, end) => any[]

              Type declaration

                • (start, end): any[]
                • 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]

              • [iterator](): Iterator<T, any, any>
              • Returns Iterator<T, any, any>

              externalfilterArray

              • filterArray<T>(nodes, match, xmlMode, root): Element[] | T[]
              • Parameters

                • externalnodes: T[]
                • externalmatch: AcceptedFilters<T>
                • externaloptionalxmlMode: boolean
                • externaloptionalroot: Document

                Returns Element[] | T[]

              externaltoArray

              • toArray<T>(this): T[]
              • Retrieve all the DOM elements contained in the jQuery set as an array.

                @example
                $('li').toArray();
                //=> [ {...}, {...}, {...} ]

                Parameters

                Returns T[]

                The contained items.