Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Column to table with jQuery

Tags:

Is it possible to add a column to an existing table like this:

<table id="tutorial" width="600" border="0">   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr>   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr>   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr> </table> 

with js?

like image 792
The Masta Avatar asked Nov 27 '13 09:11

The Masta


People also ask

How do you add a column to a table?

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.

How add and remove row from table in jQuery?

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.


2 Answers

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

like image 163
Pranay Rana Avatar answered Sep 26 '22 00:09

Pranay Rana


You can use .append() to append a new td to the rows

$('#tutorial tr').append('<td>new</td>') 

Demo: Fiddle

like image 36
Arun P Johny Avatar answered Sep 24 '22 00:09

Arun P Johny