Using detach is much faster than any other answer here:
$('#mytable').find('tbody').detach();
Remember to put the tbody element back in the table, as detach deleted it:
$('#mytable').append($('<tbody>'));
Also note that with the effectiveness of $(target).find(child) syntax of $(target).find(child) is faster than $(target > child) . What for? Sizzle!
Elapsed time to empty 3,161 rows of the table
Using the Detach () method (as shown in my example above):
- Firefox: 0.027 s
- Chrome: 0.027 s
- Edge: 1.73 s
- IE11: 4.02 s
Using the empty () method:
- Firefox: 0.055 s
- Chrome: 0.052 s
- Edge: 137.99 (may be frozen)
- IE11: freezes and never returns
Drew Nov 07 '18 at 22:19 2018-11-07 22:19
source share