Adding click events via a for loop
<p>This code works fine -- clicking first (li) yields "0" and clicking second (li) yields "1".</p>

<pre><code>$("li").eq(0).click(function () { alert(0) });
$("li").eq(1).click(function () { alert(1) });
</code></pre>

<p>However, I'd rather use a for loop.  With the following, each (li) yields "2".</p>

<pre><code>for (var i = 0; i &lt; 2; i++) {
            $("li").eq(i).click(function () { alert(i) });
        }
</code></pre>

<p>Why?  Thanks in advance.  Apologies if this is something obvious, but it's driving me crazy.</p>
