1

Does anyone know a good way to dynamically add a row to a table in jQuery?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
GuyFromOverThere
  • 471
  • 1
  • 6
  • 14
  • 1
    Possible duplicate: http://stackoverflow.com/questions/171027/add-table-row-in-jquery – Luwe Sep 02 '11 at 08:50

2 Answers2

0

Try

$('table').append('<tr><td>Foo</td></tr>');
Franquis
  • 743
  • 1
  • 5
  • 17
  • use table_id instead of table. If a page contains more then one table then it will create problem. – munjal Sep 02 '11 at 08:54
0

Technically for a cross browser implementation you should do $('table tbody').append("Foo")

Since IE doesn't automatically add the tbody for you but other browsers do.

HaloZero
  • 475
  • 4
  • 15
  • Won't this add a foo for each tbody in the table? – cHao Sep 02 '11 at 13:00
  • There's USUALLY only one tbody per table. But if you have multiple yes, this won't work. I believe the link Luwe goes into more possibilities and cases. – HaloZero Sep 02 '11 at 18:49