How replace and remove table row value by jquery

Viewed 18

Hello friend I have table as follows:

<tbody class="sellbook">
    <tr class="foobar-26">
        <td>price</td>
        <td>amount</td>
        <td>total</td>
    </tr>
    <tr class="foobar-27">
        <td>price</td>
        <td>amount</td>
        <td>total</td>
    </tr>
    <tr class="foobar-28">
        <td>price</td>
        <td>amount</td>
        <td>total</td>
    </tr>
</tbody>

I need to update data in the table row by mentioning its table row class name and need to remove also,
condition is as follows:

if value is zero , remove table row foo25 , else replace with new <td>

var newtr = "<td>" + e.message.price + "</td>" + "<td>" + e.message.amount + "</td>" + "<td>" + e.message.total + "</td>";

let trclass = "foobar-" + e.message.id + "";

if (e.message.amount == 0) {
    $(".trclass").remove();
} else {
    $(".trclass").html(newtr);
}

but nothing happens with this code, what is wrong with the code? can someone help me?

1 Answers

This isn't how you use a variable in a string:

'.trclass'

That's just a literal string. You can concatenate your value to a string:

'.' + trclass

or use the value in a template literal:

`.${trclass}`
Related