/** * Methods for modifying the DOM structure. * * @module cheerio/manipulation */ import { AnyNode } from 'domhandler'; import type { Cheerio } from '../cheerio.js'; import type { BasicAcceptedElems, AcceptedElems } from '../types.js'; /** * Create an array of nodes, recursing into arrays and parsing strings if necessary. * * @private * @category Manipulation * @param elem - Elements to make an array of. * @param clone - Optionally clone nodes. * @returns The array of nodes. */ export declare function _makeDomArray(this: Cheerio, elem?: BasicAcceptedElems, clone?: boolean): AnyNode[]; /** * Insert every element in the set of matched elements to the end of the target. * * @category Manipulation * @example * * ```js * $('
  • Plum
  • ').appendTo('#fruits'); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    • Plum
    • * //
    * ``` * * @param target - Element to append elements to. * @returns The instance itself. * @see {@link https://api.jquery.com/appendTo/} */ export declare function appendTo(this: Cheerio, target: BasicAcceptedElems): Cheerio; /** * Insert every element in the set of matched elements to the beginning of the target. * * @category Manipulation * @example * * ```js * $('
  • Plum
  • ').prependTo('#fruits'); * $.html(); * //=>
      * //
    • Plum
    • * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @param target - Element to prepend elements to. * @returns The instance itself. * @see {@link https://api.jquery.com/prependTo/} */ export declare function prependTo(this: Cheerio, target: BasicAcceptedElems): Cheerio; /** * Inserts content as the _last_ child of each of the selected elements. * * @category Manipulation * @example * * ```js * $('ul').append('
  • Plum
  • '); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    • Plum
    • * //
    * ``` * * @see {@link https://api.jquery.com/append/} */ export declare const append: (this: Cheerio, ...elems: [(this: AnyNode, i: number, html: string) => BasicAcceptedElems] | BasicAcceptedElems[]) => Cheerio; /** * Inserts content as the _first_ child of each of the selected elements. * * @category Manipulation * @example * * ```js * $('ul').prepend('
  • Plum
  • '); * $.html(); * //=>
      * //
    • Plum
    • * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @see {@link https://api.jquery.com/prepend/} */ export declare const prepend: (this: Cheerio, ...elems: [(this: AnyNode, i: number, html: string) => BasicAcceptedElems] | BasicAcceptedElems[]) => Cheerio; /** * 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. * * @category Manipulation * @example * * ```js * const redFruit = $('
    '); * $('.apple').wrap(redFruit); * * //=>
      * //
      * //
    • Apple
    • * //
      * //
    • Orange
    • * //
    • Plum
    • * //
    * * const healthy = $('
    '); * $('li').wrap(healthy); * * //=>
      * //
      * //
    • Apple
    • * //
      * //
      * //
    • Orange
    • * //
      * //
      * //
    • Plum
    • * //
      * //
    * ``` * * @param wrapper - The DOM structure to wrap around each element in the selection. * @see {@link https://api.jquery.com/wrap/} */ export declare const wrap: (this: Cheerio, wrapper: AcceptedElems) => Cheerio; /** * 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. * * @category Manipulation * @example * * ```js * const redFruit = $('
    '); * $('.apple').wrapInner(redFruit); * * //=>
      * //
    • * //
      Apple
      * //
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * * const healthy = $('
    '); * $('li').wrapInner(healthy); * * //=>
      * //
    • * //
      Apple
      * //
    • * //
    • * //
      Orange
      * //
    • * //
    • * //
      Pear
      * //
    • * //
    * ``` * * @param wrapper - The DOM structure to wrap around the content of each element * in the selection. * @returns The instance itself, for chaining. * @see {@link https://api.jquery.com/wrapInner/} */ export declare const wrapInner: (this: Cheerio, wrapper: AcceptedElems) => Cheerio; /** * The .unwrap() function, removes the parents of the set of matched elements * from the DOM, leaving the matched elements in their place. * * @category Manipulation * @example without selector * * ```js * const $ = cheerio.load( * '
    \n

    Hello

    \n

    World

    \n
    ' * ); * $('#test p').unwrap(); * * //=>
    * //

    Hello

    * //

    World

    * //
    * ``` * * @example with selector * * ```js * const $ = cheerio.load( * '
    \n

    Hello

    \n

    World

    \n
    ' * ); * $('#test p').unwrap('b'); * * //=>
    * //

    Hello

    * //

    World

    * //
    * ``` * * @param selector - 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 The instance itself, for chaining. * @see {@link https://api.jquery.com/unwrap/} */ export declare function unwrap(this: Cheerio, selector?: string): Cheerio; /** * 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. * * @category Manipulation * @example With markup passed to `wrapAll` * * ```js * const $ = cheerio.load( * '
    First
    Second
    ' * ); * $('.inner').wrapAll("
    "); * * //=>
    * //
    * //
    First
    * //
    Second
    * //
    * //
    * ``` * * @example With an existing cheerio instance * * ```js * const $ = cheerio.load( * 'Span 1StrongSpan 2' * ); * const wrap = $('

    '); * $('span').wrapAll(wrap); * * //=>
    * //

    * // * // * // Span 1 * // Span 2 * // * // * //

    * //
    * // Strong * ``` * * @param wrapper - The DOM structure to wrap around all matched elements in the * selection. * @returns The instance itself. * @see {@link https://api.jquery.com/wrapAll/} */ export declare function wrapAll(this: Cheerio, wrapper: AcceptedElems): Cheerio; /** * Insert content next to each element in the set of matched elements. * * @category Manipulation * @example * * ```js * $('.apple').after('
  • Plum
  • '); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Plum
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @param content - HTML string, DOM element, array of DOM elements or Cheerio * to insert after each element in the set of matched elements. * @returns The instance itself. * @see {@link https://api.jquery.com/after/} */ export declare function after(this: Cheerio, ...elems: [(this: AnyNode, i: number, html: string) => BasicAcceptedElems] | BasicAcceptedElems[]): Cheerio; /** * Insert every element in the set of matched elements after the target. * * @category Manipulation * @example * * ```js * $('
  • Plum
  • ').insertAfter('.apple'); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Plum
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @param target - Element to insert elements after. * @returns The set of newly inserted elements. * @see {@link https://api.jquery.com/insertAfter/} */ export declare function insertAfter(this: Cheerio, target: BasicAcceptedElems): Cheerio; /** * Insert content previous to each element in the set of matched elements. * * @category Manipulation * @example * * ```js * $('.apple').before('
  • Plum
  • '); * $.html(); * //=>
      * //
    • Plum
    • * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @param content - HTML string, DOM element, array of DOM elements or Cheerio * to insert before each element in the set of matched elements. * @returns The instance itself. * @see {@link https://api.jquery.com/before/} */ export declare function before(this: Cheerio, ...elems: [(this: AnyNode, i: number, html: string) => BasicAcceptedElems] | BasicAcceptedElems[]): Cheerio; /** * Insert every element in the set of matched elements before the target. * * @category Manipulation * @example * * ```js * $('
  • Plum
  • ').insertBefore('.apple'); * $.html(); * //=>
      * //
    • Plum
    • * //
    • Apple
    • * //
    • Orange
    • * //
    • Pear
    • * //
    * ``` * * @param target - Element to insert elements before. * @returns The set of newly inserted elements. * @see {@link https://api.jquery.com/insertBefore/} */ export declare function insertBefore(this: Cheerio, target: BasicAcceptedElems): Cheerio; /** * Removes the set of matched elements from the DOM and all their children. * `selector` filters the set of matched elements to be removed. * * @category Manipulation * @example * * ```js * $('.pear').remove(); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Orange
    • * //
    * ``` * * @param selector - Optional selector for elements to remove. * @returns The instance itself. * @see {@link https://api.jquery.com/remove/} */ export declare function remove(this: Cheerio, selector?: string): Cheerio; /** * Replaces matched elements with `content`. * * @category Manipulation * @example * * ```js * const plum = $('
  • Plum
  • '); * $('.pear').replaceWith(plum); * $.html(); * //=>
      * //
    • Apple
    • * //
    • Orange
    • * //
    • Plum
    • * //
    * ``` * * @param content - Replacement for matched elements. * @returns The instance itself. * @see {@link https://api.jquery.com/replaceWith/} */ export declare function replaceWith(this: Cheerio, content: AcceptedElems): Cheerio; /** * Empties an element, removing all its children. * * @category Manipulation * @example * * ```js * $('ul').empty(); * $.html(); * //=>
      * ``` * * @returns The instance itself. * @see {@link https://api.jquery.com/empty/} */ export declare function empty(this: Cheerio): Cheerio; /** * Gets an HTML content string from the first selected element. * * @category Manipulation * @example * * ```js * $('.orange').html(); * //=> Orange * * $('#fruits').html('
    • Mango
    • ').html(); * //=>
    • Mango
    • * ``` * * @returns The HTML content string. * @see {@link https://api.jquery.com/html/} */ export declare function html(this: Cheerio): string | null; /** * Replaces each selected element's content with the specified content. * * @category Manipulation * @example * * ```js * $('.orange').html('
    • Mango
    • ').html(); * //=>
    • Mango
    • * ``` * * @param str - The content to replace selection's contents with. * @returns The instance itself. * @see {@link https://api.jquery.com/html/} */ export declare function html(this: Cheerio, str: string | Cheerio): Cheerio; /** * Turns the collection to a string. Alias for `.html()`. * * @category Manipulation * @returns The rendered document. */ export declare function toString(this: Cheerio): string; /** * Get the combined text contents of each element in the set of matched * elements, including their descendants. * * @category Manipulation * @example * * ```js * $('.orange').text(); * //=> Orange * * $('ul').text(); * //=> Apple * // Orange * // Pear * ``` * * @returns The text contents of the collection. * @see {@link https://api.jquery.com/text/} */ export declare function text(this: Cheerio): string; /** * Set the content of each element in the set of matched elements to the specified text. * * @category Manipulation * @example * * ```js * $('.orange').text('Orange'); * //=>
      Orange
      * ``` * * @param str - The text to set as the content of each matched element. * @returns The instance itself. * @see {@link https://api.jquery.com/text/} */ export declare function text(this: Cheerio, str: string | ((this: AnyNode, i: number, text: string) => string)): Cheerio; /** * Clone the cheerio object. * * @category Manipulation * @example * * ```js * const moreFruit = $('#fruits').clone(); * ``` * * @returns The cloned object. * @see {@link https://api.jquery.com/clone/} */ export declare function clone(this: Cheerio): Cheerio; //# sourceMappingURL=manipulation.d.ts.map