Can I $.wrap() around a collection of elements in an array?

后端 未结 3 1436
长情又很酷
长情又很酷 2021-02-09 00:07

Let\'s say I have a collection of \'items\' like so:

3条回答
  •  日久生厌
    2021-02-09 00:38

    Try wrapAll method instead:

    $(".group").wrapAll("
    ");

    DEMO: http://jsfiddle.net/LanMt/3/


    For wrapping the separate groups of .group elements you can use the following:

    $(".group").map(function() {
        if (!$(this).prev().hasClass("group")) {
            return $(this).nextUntil(":not(.group)").andSelf();
        }
    }).wrap("
    ");

    DEMO: http://jsfiddle.net/LanMt/5/

    The code above was assembled with the help of @Jon's answer.

提交回复
热议问题