Can I use Jquery to insert a closing tag and an opening tag inside a dynamic table?

前端 未结 3 920
小蘑菇
小蘑菇 2020-12-21 06:43

I\'m trying to use the code below to dynamically add closing tag followed by opening so that i creates a new row every three cells. Almost working, DOM inspector shows a T

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 07:07

    Another approach is to detach all the td elements, and then split them into groups of 3 using splice:

    var td = $('tr td').detach();
    $('tr').remove();
    while(td.length>0){ 
     $(td.splice(0,3)).wrapAll('').parent().appendTo('tbody');   
    }
    

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

提交回复
热议问题