Using jQuery, how do I delete all rows in a table except the first? This is my first attempt at using index selectors. If I understand the examples correctly, the following should work:
$(some table selector).remove("tr:gt(0)");
which I would read as "Wrap some table in a jQuery object, then remove all 'tr' elements (rows) where the element index of such rows is greater than zero". In reality, it executes without generating an error, but doesn't remove any rows from the table.
What am I missing, and how do I fix this? Of course, I could use straight javascript, but I'm having so much fun with jQuery that I'd like to solve this using jQuery.
-Sorry this is very late reply.
The easiest way i have found to delete any row (and all other rows through iteration) is this
$('#rowid','#tableid').remove();
The rest is easy.
Your selector doesn't need to be inside your remove.
It should look something like:
Which means select every row except the first in the table with ID of tableID and remove them from the DOM.
I remember coming across that 'slice' is faster than all other approaches, so just putting it here.
Easiest way :
-first reference the table
-get the list of elements and slice it and remove the selected elements of the list
This should work: