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! 🙂
If the row will always be assigned to the element before the footer row, then your idea to add an ID would seem to make sense.
If you don’t want to use an ID, then use an idea similar to your
:firstselector. DoinsertBefore('#content tr:last');