How to wrap (to group) a list of elements into another element with jquery?

后端 未结 3 1173
南旧
南旧 2020-12-10 17:53

I have the following structure.

  • 3条回答
    •  佛祖请我去吃肉
      2020-12-10 18:52

      You can do it with wrapAll:

      var a = $('li');
      do $(a.slice(0,3)).wrapAll('
        '); while((a = a.slice(3)).length>0)

      example: http://jsfiddle.net/niklasvh/mZr4h/

    提交回复
    热议问题