How to clone() a element n times?
问题 I have a dynamic table that I want to attach <col> elements with jQuery. I have this: var tds = jQuery("tr > td").length; // count how many tds jQuery("#colgroup-compare > col").clone() // clone .appendTo('#colgroup-compare'); // and append Obviously this only appends 1 <col> , I want to append (n) numbers. How would I do this? I have the length, I have the clone ability, now how do I combine it? 回答1: With a loop : var $col = $("#colgroup-compare > col"); for(var i = 0; i < n; i++){ $col