How can I change this code to make it work?
<p>I'm starting with Flask, and I'm having some problems with jQuery and (I think) Flask's templating system. What I wanted to do is very simple: I've included a <em>behavior.js</em> script in the layout master template <em>layout.html</em>, after the jQuery library. Its contents are:</p>

<pre><code>jQuery(document).ready(function() {
    var events = $("#fake_grid td");
    while(events.length &gt; 0) {
        $("#the_grid").append($("&lt;tr/&gt;").append(events.slice(0, 3)));
    }
    $("#fake_grid").remove();
});
</code></pre>

<p>When I try to execute this, my browser crashes, and I can't figure it out why and how to fix it. I've been thinking about jQuery doesn't loading properly or loading after my script, but I've checked with FireBug and everything in that matter works fine. I've tried replacing all that code with an alert() and that worked fine, too. I've tried including my .js in the child template <em>index.html</em>, in several different ways, but it wasn't that, for sure. Maybe it's something with the document readyness thing.</p>

<p>If it is something else, I'm unable to see it, and that's making me really anxious. So, any advice in what to do about this? What I'm doing wrong? Thanks in advance.</p>
