Home > Javascript > Dynamically Removing Rows From A Table

Dynamically Removing Rows From A Table

September 22nd, 2009

My table’s HTML looks like,

<table id="ppltbl">
  <tbody>
    <tr>
      <td>..</td>
      <td>..</td>
    </tr>
    <!-- Other rows come here -->  
</tbody>
</table>

Here’s the jQuery code to remove all rows except the first 3 (first index is 0),

$("#ppltbl").find("tr:gt(2)").remove();

Here’s the jQuery code to remove all even rows including the first row whose index is 0,

$("#ppltbl").find("tr:even").remove();

Here’s the jQuery code to remove all even rows after the first row,

$("#ppltbl").find("tr:even:gt(0)").remove();

For other combinations, please refer to jQuery selectors documentation at http://docs.jquery.com/Selectors

Categories: Javascript Tags:
Comments are closed.