最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to clone a <tr> element without data but only the structure by using jQuery? - Stack Overflow

programmeradmin0浏览0评论

Is there a quick way to clone a <tr> element without its content in cells? Basically to have a pure <tr> element having only the same structure as the original?

Is there a quick way to clone a <tr> element without its content in cells? Basically to have a pure <tr> element having only the same structure as the original?

Share Improve this question edited Dec 21, 2016 at 14:18 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 1, 2011 at 8:39 pencilCakepencilCake 53.3k87 gold badges236 silver badges376 bronze badges 2
  • Do you mean a deep clone or a shallow one? – Frédéric Hamidi Commented Jun 1, 2011 at 8:41
  • By deep clone, you mean all the child elements within table cells? – pencilCake Commented Jun 1, 2011 at 8:43
Add a ment  | 

1 Answer 1

Reset to default 12

If you want a deep clone of the element without the text content, you can write something like:

var $cloned = $("tr").clone().children().text("").end();
发布评论

评论列表(0)

  1. 暂无评论