Adding a column to all rows with jquery

How to add a column to all rows (including header row) using jQuery. The added column will be the first column.

+4
source share
2 answers

What I understand from your question, here is the code for you

$('#tableID tr:first ').append("<td class='TableHeading'>second</td>"); $('#tableID tr:not(:first)').each(function(){ $(this).append("<td class='tdMiddleCells'>second</td>"); }); 

Here you can scroll through the rows of the table and add columns to each row. this will add the column to the last place, the first statement will add the column as a heading, and then the remaining rows.

hope this helps.

+11
source

This should do it:

 $("tr:first").append("th"); $("tr:not(:first)").append("td"); 
0
source

All Articles