Wrapping a div around every three divs

前端 未结 3 1154
渐次进展
渐次进展 2021-01-05 12:35

Say I have 6 child divs and they don\'t have unique identifiers:

3条回答
  •  广开言路
    2021-01-05 13:25

    Wow, nice challenging question =)

    while(($children = $(':not(.parent)>.child:lt(3)')).length) {
        $children
            .parent()
            .append(
                $('
    ') .append($children.remove()) ); }

    Edit: Didn't know about the wrapAll method, so:

    while(($children = $(':not(.parent)>.child:lt(3)')).length) {
        $children.wrapAll($('
    ')); }

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题