How to clone two columns in a table using jQuery

后端 未结 5 1590
执笔经年
执笔经年 2021-01-18 15:44

I am trying to clone 2 columns from a table to a new table using jQuery. The source table is below:



        
      
      
      
5条回答
  •  孤城傲影
    2021-01-18 16:21

    Try

    $('#sourceT tr').clone().appendTo('#targetT')
    $('#targetT tr').find('td :gt(1)').remove();
    

    Demo: Fiddle

    OR

    var clone = $('#sourceT tr').clone()
    clone.find('td :gt(1)').remove();
    clone.appendTo('#targetT')
    

    Demo: Fiddle

    I may prefer the OR portion since the dom is updated only once

提交回复
热议问题