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?
With a loop :
You can’t use
jQuery("#colgroup-compare > col").clone().appendTo('#colgroup-compare');in your loop because that would append more cols at iterations > 0…This can be optimized :
EDIT : to count the
thin your first row, you may do this :(this avoid counting on more than one row)
Demonstration