Function wrapInner

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

    Returns

    The instance itself, for chaining.

    See

    https://api.jquery.com/wrapInner/

    Type Parameters

    Parameters

    Returns Cheerio<T>