What is the best method in jQuery to add an additional row to a table as the last row?
Is this acceptable?
$(\'#myTable\').append(\'
-
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.
var ninja_row = $('#banner_holder').find('tr');
if( $('#my_table tbody tr').length > 5){
$('#my_table tbody tr').filter(':nth-child(5)').after(ninja_row);
}else{
$('#my_table tr:last').after(ninja_row);
}
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.
- 热议问题