12

Possible Duplicate:
What is the best way to remove a table row with jQuery?

If I have table with 3 rows using tr tag, how do I remove the first row (index 0) with either jquery or some other javascript?

Community
  • 1
  • 1
Varia
  • 167
  • 1
  • 1
  • 8

4 Answers4

11

try

$("tr").eq(0).remove();

However, like @Gregg said, take a look at official docs

gilly3
  • 87,962
  • 25
  • 144
  • 176
Cristian
  • 327
  • 2
  • 9
10

This would remove the 3rd row in a table.

$("table tr:eq(2)").remove();

Also, don't forget to use <thead> and <tbody> in your <table>. It makes things more accessible and helps if you want to use a plug-in for sorting later down the road.

pixelbobby
  • 4,368
  • 5
  • 29
  • 49
3

Here's the "some other javascript" approach, which is itself very simple:

document.getElementById("myTable").deleteRow(0);
gilly3
  • 87,962
  • 25
  • 144
  • 176
2

The jQuery docs are a great resource for this kind of thing...

$("tr:first").remove()
gilly3
  • 87,962
  • 25
  • 144
  • 176
Gregg
  • 34,973
  • 19
  • 109
  • 214