0

I'm working in building an Jquery mobile application, in that I had created a table, I need to update that table rows from DB.

This is my html...

  <table style="width:100%;" id="cart_table">
     <tr>
       <th>Item</th>
       <th>Qty</th>
       <th>Price</th>
       <th>Delete</th>
     </tr>       </table>

i called a showall() method to show all cart items in it when the cart button is clicked ..

 var row = ('<tr><td align="center"><a>'+cartitem1+'</a></td> <td align="center"><a>'+cart_qty+'</a></td> <td align="center"><a>'+cart_price+'</a></td><td align="center"><a><img src=""/></a></td></tr>');
      $("#cart_table").html(row.html());

This will be in for loop.I had put one row for sample .. Help me to update my row dynamically

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
GK_
  • 1,212
  • 1
  • 12
  • 26

1 Answers1

0

I have changed this line

$("#cart_table").html(row.html());

to

$('#cart_table tr:last').after(row); 

it works..

Thanks to Luke Bennett

Community
  • 1
  • 1
GK_
  • 1,212
  • 1
  • 12
  • 26
  • or use `.append()`. `.html()` overwrites existing elements. – Omar Mar 07 '14 at 09:13
  • 2
    I know, you need to use `.append()`, `.prepend()`, `.after()`, `.before()` not [`.html()`](https://api.jquery.com/html/). – Omar Mar 07 '14 at 09:43