The table is a direct child of body, and when body gets removed (which it will be) the table will be a top level element. Change
$div = $('table.targetTable', html);
to
$div = $(html).filter('table.targetTable');
and to avoid other issues, use:
$div = $($.parseHTML(html)).filter('table.targetTable');