Best way to add tr element mid-way through a list of table rows - jQuery

Posted by soulBit on Stack Overflow See other posts from Stack Overflow or by soulBit
Published on 2010-05-22T20:48:26Z Indexed on 2010/05/22 20:50 UTC
Read the original article Hit count: 137

Filed under:

Hi all, first post on the site!

I'm looking for some help inserting tr elements mid-way through a simple table like the one below:

<table id="content">  
<tr class="item">  
<td><p>header content</p></td>  
</tr>  
<tr class="item">  
<td><p>footer content</p></td>  
</tr>  
</table>

I am adding elements using jQuery with the following code:

$('<tr class="item" />').insertAfter('#content tr:first');

However after adding an element using this command, I would like to add some more (but after the last added item, not at the top of the list)

Im sure there are simple ways of doing this (by assigning an id to the footer element, and using .insertBefore('#footer') for example) but it would be interesting to know some different techniques that could be used. Thanks in advance! :)

© Stack Overflow or respective owner

Related posts about jQuery