Detach Elements to Work With Them
Prev Chapter 9. Performance Best Practices Next

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.

var $table = $('#myTable');
var $parent = table.parent();

$table.detach();
// ... add lots and lots of rows to table
$parent.append(table);

Copyright Rebecca Murphey, released under the Creative Commons Attribution-Share Alike 3.0 United States license.


Prev Up Next
Use Event Delegation Home Use Stylesheets for Changing CSS on Many Elements