How can add database table ID into table row as class or ID

Viewed 25

I want to add database table ID to table row as a class or ID.

$.each(response.sellorderbookdata, function(key, item) {
  if (item.total !== 0) {
    $("tr").addClass(item.id);
    $('tbody.sellbook').append('<tr>\
     <td class="red-bg-100">' + item.price + '</td>\
     <td class="pink-bg-90">' + item.amount + '</td>\
     <td class="white-bg-70">' + item.total + '</td>\
     </tr>');
  }
});
}

Will it work? The data inside table rows are dynamically pulled from a database. It needs to update whenever data is retrieved and I want to replace some text value in the table cell by mention table row.

How can I make it work?

1 Answers

Use string concatenation rather than jquery

$.each(response.sellorderbookdata, function(key, item) {
  if (item.total !== 0) {
    $('tbody.sellbook').append('<tr class="' + item.id + '">'\
     <td class="red-bg-100">' + item.price + '</td>\
     <td class="pink-bg-90">' + item.amount + '</td>\
     <td class="white-bg-70">' + item.total + '</td>\
     </tr>');
  }
});
}
Related