Is it possible to add a column to an existing table like this:
<table id="tutorial" width="600" border="0"> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table>
with js?
Click in a cell to the left or right of where you want to add a column. Under Table Tools, on the Layout tab, do one of the following: To add a column to the left of the cell, click Insert Left in the Rows and Columns group. To add a column to the right of the cell, click Insert Right in the Rows and Columns group.
Adding a row: Then we will use the jQuery “click” event to detect a click on the add row button and then use the . append() method of jQuery to add a row in the table. Each row element has been assigned an id Ri that we will later use to delete a row. Each element has a row index column and remove the button column.
you can do like this
$('#tutorial').find('tr').each(function(){ $(this).find('td').eq(n).after('<td>new cell added</td>'); });
n can be replaced by the number after which column you want to add new column
You can use .append() to append a new td
to the rows
$('#tutorial tr').append('<td>new</td>')
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With