I thought this might be a fast way to remove the contents of a very large table (3000 rows):
$jq(\"tbody\", myTable).remove();
But it\'s taking
Using detach is magnitudes faster than any of the other answers here:
$('#mytable').find('tbody').detach();
Don't forget to put the tbody element back into the table since detach removed it:
$('#mytable').append($(''));
Also note that when talking efficiency $(target).find(child)
syntax is faster than $(target > child)
. Why? Sizzle!
Elapsed Time to Empty 3,161 Table Rows
Using the Detach() method (as shown in my example above):
- Firefox: 0.027s
- Chrome: 0.027s
- Edge: 1.73s
- IE11: 4.02s
Using the empty() method:
- Firefox: 0.055s
- Chrome: 0.052s
- Edge: 137.99s (might as well be frozen)
- IE11: Freezes and never returns
- 热议问题