What is the best method in jQuery to add an additional row to a table as the last row?
Is this acceptable?
$('#myTable').append('<tr><td>my data</td><td>more data</td></tr>');
Are there limitations to what you can add to a table like this (such as inputs, selects, number of rows)?
My solution:
usage:
For the best solution posted here, if there's a nested table on the last row, the new row will be added to the nested table instead of the main table. A quick solution (considering tables with/without tbody and tables with nested tables):
Usage example:
Write with a javascript function
In a simple way:
I found this AddRow plugin quite useful for managing table rows. Though, Luke's solution would be the best fit if you just need to add a new row.
To add a good example on the topic, here is working solution if you need to add a row at specific position.
The extra row is added after the 5th row, or at the end of the table if there are less then 5 rows.
I put the content on a ready (hidden) container below the table ..so if you(or the designer) have to change it is not required to edit the JS.