Skip to the content.

$.fn.wrap(html)

Wrap each item in the collection with its own copy of the supplied content.

If the wrapper has nested children, each element is placed inside the deepest descendant. Pass a callback to compute a different wrapper per element.

Signatures

wrap(html: Selector | ((this: Element, index: number) => Selector)): this;

Parameters

Returns

The original Dabby collection for chaining.

Examples

import $ from "dabbyjs";
import "dabbyjs/manipulation/wrap/wrap";

// Wrap each thumbnail with its own zoom link
$("img.thumbnail").wrap("<a class='zoom'></a>");
import $ from "dabbyjs";
import "dabbyjs/manipulation/wrap/wrap";

// Wrapper with nested elements — items end up in the deepest descendant
$(".chip").wrap("<div class='chip-row'><span class='chip-inner'></span></div>");
import $ from "dabbyjs";
import "dabbyjs/manipulation/wrap/wrap";

// Compute the wrapper per element
$("p").wrap(function (index) {
    return `<section data-index='${index}'></section>`;
});

See also