Using Jquery to insert a row in table

Example:

<table width='100%'>
<tr><td>something</td><td>else here</td></tr>
<tr><td>something2</td><td>else here2</td></tr>
</table>

If you want place following code at the end of the table.

<tr><td>something3</td><td>else here3</td></tr>

Like:

<table width='100%'>
<tr><td>something</td><td>else here</td></tr>
<tr><td>something2</td><td>else here2</td></tr>
<tr><td>something3</td><td>else here3</td></tr>
</table>

You can use jquery to insert a row in top of table:

$('table').append('<tr><td>something3</td><td>else here3</td></tr>');

or

$('<tr><td>something3</td><td>else here3</td></tr>').appendTo('table');

If you want place it code at the top of the table like:

<table width='100%'>
<tr><td>something</td><td>else here</td></tr>
<tr><td>something2</td><td>else here2</td></tr>
<tr><td>something3</td><td>else here3</td></tr>
</table>

You can use jquery to insert a row in end of table:

$('table').prepend('<tr><td>something3</td><td>else here3</td></tr>');

or

$('<tr><td>something3</td><td>else here3</td></tr>').prependTo('table');
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.