A. Z. A. Z. - 1 month ago 4
jQuery Question

How to generate rowspan with jQuery?

I want to insert a rowspan after every first td in every table, but I can't.

I started searching and made this code. It doesn't work, but may tell more about thing I need.

$("table").each(function(){
var rowcount = $("tr").length;
var insert = ('<td rowspan="' + rowcount + '" class="table-rowspan">&nbsp;</td>')
$("table td:first").after(insert);
});

Answer

Hiya please try this demo http://jsfiddle.net/kAzfQ/ updated demo http://jsfiddle.net/kAzfQ/3/

Solution will add columns fooo after every first td one first row. Demo includes 2 table.

Please let me know if I am missing anything,

Hope this helps,

Note You can add row count back I have excluded it for this demo. to show you the td append after first row first td. B-)

code

$('table').each(function() {

    var rowcount = $("tr").length;

    $(this).find('td').eq(0).after('<td rowspan=rowcount class="table-rowspan">==>fooo <== </td>');

});‚Äč
Comments