JavaScript/jQuery weirdness concerning re-insertion of an element
<p>I've got a good sized script(200 lines or so) and I'm having problems with a seemingly trivial element of the code. I have a page and I am replacing the entire body with JS, however I need to re-attach a form so it can still be submitted after the page restructuring. (That submission will be triggered through JS.) However, what's happening is the code ceases to run following the <code>insertAfter()</code> call (Assumedly it's crashing within that function). As a result, the second alert and all subsequent code is not being run. Help!</p>

<pre><code>var form = $("form").detach().hide();
$("body").html(newPage);
alert("HI");
form.insertAfter("#grades");
alert("HI2");
</code></pre>

<p>Note that <code>newPage</code> is a string.</p>
