Trilium Backend API
    Preparing search index...
    • 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.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • wrapper: 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>