Home > Net >  How replace and remove table row value by jquery
How replace and remove table row value by jquery

Time:09-22

hello friend i have table as follow


  <tbody >
                                <tr >
                                       <td>price</td>
                                       <td>amount</td>
                                       <td>total</td>
                               </tr>
                             <tr >
                                       <td>price</td>
                                       <td>amount</td>
                                       <td>total</td>
                               </tr>
                             <tr >
                                       <td>price</td>
                                       <td>amount</td>
                                       <td>total</td>
                               </tr>
                                    </tbody>

i need to update data in table row by mention its table row class name and need to remove also,
condition is as folow
if value is zero , remove table row foo25 , else replace with new

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 happen with this code , what wrong in code . can someone help me.

CodePudding user response:

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