开发者

jquery selecting and copying tr

I wish to duplicate a tr tag in jquery. I have the following. The issue with this code is that $(rowId) doesn't include the "tr" but just the contents inside it. So the first tag is a <td> not a <tr>. How can select this element also.

      $('.addLine').click(fu开发者_如何转开发nction () {
          var rowId = $(this).attr('rel');
          var rowId = "#" + rowId;
          var newRow = $(rowId);
          var htmlStr = $(newRow).html(); 
          $(newRow).append(htmlStr);

      });


.html() returns the inside of the element selected, you can use .clone() to make a copy of the entire element, which you can append.

 $('.addLine').click(function () {
      var rowId = $(this).attr('rel');
      var newRow = $("#"+rowId).clone().appendTo("youTableOrSomething");
  });


Try this one

$('.addLine').click(function () {
          var rowId = $(this).attr('rel');
          var rowId = "#" + rowId;
          var newRow = $(rowId).parent();
          var htmlStr = $(newRow).html(); 
          $(newRow).append(htmlStr);

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜