Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new rows to an existing table

I have the following code which creates a new table.

var html = '<table>';
$.each( results.d, function( index, record ) {
    html += '<tr><td>' + record.ClientCode + '</td></tr>';
});
html += '</table>';
$("#divResults").append(html);

How do I change this so instead of creating a brand new table each time, it adds tr and td data to an already existing table? Where the new data always gets added after the last existing tr/td in the table?

like image 315
oshirowanen Avatar asked Dec 30 '25 01:12

oshirowanen


1 Answers

If you already have created html table in #divResults div, you can try:

$.each( results.d, function( index, record ) {
    $('#divResults table tr:last').after('<tr><td>' + record.ClientCode + '</td></tr>');
});

Example

like image 62
Naveed Avatar answered Dec 31 '25 18:12

Naveed