Detach Elements to Work with Them

jQuery

Detach Elements to Work with Them

The DOM is slow; you want to avoid manipulating it as much as possible. jQuery introduced $.fn.detach in version 1.4 to help address this issue, allowing you to remove an element from the DOM while you work with it.

1
2
3
4
5
6
7
                          
var $table = $("#myTable");
var $parent = $table.parent();
$table.detach();
// ... add lots and lots of rows to table
$parent.append( $table );