Inserting a table column with jQuery
- by fudgey
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>');
})
})