A. Z. A. Z. - 1 year ago 80
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.

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

Answer Source

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-)


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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download