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)?
Here is some hacketi hack code. I wanted to maintain a row template in an HTML page. Table rows 0...n are rendered at request time, and this example has one hardcoded row and a simplified template row. The template table is hidden, and the row tag must be within a valid table or browsers may drop it from the DOM tree. Adding a row uses counter+1 identifier, and the current value is maintained in the data attribute. It guarantees each row gets unique URL parameters.
I have run tests on Internet Explorer 8, Internet Explorer 9, Firefox, Chrome, Opera, Nokia Lumia 800, Nokia C7 (with Symbian 3), Android stock and Firefox beta browsers.
PS: I give all credits to the jQuery team; they deserve everything. JavaScript programming without jQuery - I don't even want think about that nightmare.
I was having some related issues, trying to insert a table row after the clicked row. All is fine except the .after() call does not work for the last row.
I landed up with a very untidy solution:
create the table as follows (id for each row):
etc ...
and then :
If you are using Datatable JQuery plugin you can try.
Refer Datatables fnAddData Datatables API
In my opinion the fastest and clear way is
here is demo Fiddle
Also I can recommend a small function to make more html changes
If you use my string composer you can do this like
Here is demo Fiddle
This is my solution