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.


    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>

    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.


      Parameters

      • externalthis: Cheerio<T>
      • externalname: string

        Name of the attribute.

      Returns string | undefined

      The attribute's value.

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

    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.


      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.

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

    externalhasClass

    • hasClass<T>(this, className): boolean
    • 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');
      //=> true

    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.


      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.


      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.

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

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

    externalremoveAttr

    • removeAttr<T>(this, name): Cheerio<T>
    • 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>

    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.


      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>

      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.


        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>

        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.


          Parameters

          Returns string | undefined | string[]

          The value.

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

        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.


          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.


          Parameters

          Returns string

          The serialized form.

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

        externalserializeArray

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


          Parameters

          Returns SerializedField[]

          The serialized form.

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

        Manipulation

        externalafter

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

        externalappend

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

        externalappendTo

        • appendTo<T>(this, target): Cheerio<T>
        • 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>

        externalbefore

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

        externalclone

        externalempty

        externalhtml

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


          Parameters

          Returns string | null

          The HTML content string.

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

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

        externalinsertAfter

        • insertAfter<T>(this, target): Cheerio<T>
        • 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>

        externalinsertBefore

        • insertBefore<T>(this, target): Cheerio<T>
        • 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>

        externalprepend

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

        externalprependTo

        • prependTo<T>(this, target): Cheerio<T>
        • 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>

        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.


          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>

        externalreplaceWith

        • replaceWith<T>(this, content): Cheerio<T>
        • 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>

        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.


          Parameters

          Returns string

          The text contents of the collection.

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

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

        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.


          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>

        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>

        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.


          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>

        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.


          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>

        Traversing

        externaladd

        • add<S, T>(this, other, context): Cheerio<S | T>
        • 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;
          //=> 2

        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.


          Parameters

          • externalthis: Cheerio<T>
          • externaloptionalselector: string

            Selector for the elements to add.

          Returns Cheerio<AnyNode>

          The combined set.

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

        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();
          //=> Pear

        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.


          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>]

        externalcontents

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


          Parameters

          Returns Cheerio<AnyNode>

          The children.

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

        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.


          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, Pear

          externalend

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


            Parameters

            Returns Cheerio<AnyNode>

            The previous state of the set of matched elements.

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

          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();
            //=> Pear

          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.

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

            externalfind

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


              Parameters

              Returns Cheerio<Element>

              The found elements.

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

            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.


              Parameters

              • externalthis: Cheerio<T>
              • externali: number

                Element to retrieve.

              Returns T | undefined

              The element at the ith position.

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

            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

              Returns Cheerio<AnyNode | Element>

              The filtered collection.

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

            externalindex

            • index<T>(this, selectorOrNeedle): number
            • 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'));
              //=> 1

            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.

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

              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');
                //=> true

              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>]

              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>]

              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.


                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 === el
                return $(this).attr('class') === 'orange';
                }).length; //=> 2

              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');
                //=> fruits

              externalparents

              • Get a set of parents filtered by selector of 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;
                //=> 1

              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;
                //=> 1

              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');
                //=> true

              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>]

              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>]

              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;
                //=> 1

              externalslice

              • slice<T>(this, start, end): Cheerio<T>
              • 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;
                //=> 1

              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.


                Parameters

                Returns T[]

                The contained items.

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