Add Column to table with jQuery

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?

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

You mean column not row?

$('#tutorial tr').each(function()
{
    $(this).append('<td></td>');
});

Which selects the <tr> element inside id “tutorial” (that is your table is this case) and append new contents behind its original contents

An alternative option to those above is to create the column together with the other and a style of display:none; and then using the method .Show() to display.


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Difference between request.getSession().getId() and request.getSession(false)?

Similar Posts