Inserting a table column with jQuery

Posted by fudgey on Stack Overflow See other posts from Stack Overflow or by fudgey
Published on 2009-10-31T19:18:20Z Indexed on 2010/06/13 21:42 UTC
Read the original article Hit count: 308

Filed under:
|
|

I have a table of data that I need to dynamically add a column to. Lets say I have this basic table to start with:

<table>
 <tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr>
 <tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr>
 <tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr>
</table>

I would like to insert a column between cell 1 and cell 2 in each row... I've tried this but it just isn't working like I expect... maybe I need more caffeine.

$(document).ready(function(){
 $('table').find('tr').each(function(){
  $(this).prepend('<td>cell 1a</td>');
 })
})

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about table