Add elements to jquery object inside each loop
<p>I'm sure i'm missing something here, using this code:</p>

<pre><code>var $divs = $();
$.each([1, 2, 3], function (i, val) {
    $divs.add($('&lt;div&gt;' + val + '&lt;/div&gt;'));
});
alert($divs.length); //output 0 { not really expected }
</code></pre>

<p><code>$divs</code> is empty object.</p>

<p>To get expected behaviour, i need to reaffect to var <code>$divs</code> like this:</p>

<pre><code>var $divs = $();
$.each([1, 2, 3], function (i, val) {
    $divs = $divs.add($('&lt;div&gt;' + val + '&lt;/div&gt;'));
});
alert($divs.length); //output 3 { as expected }
</code></pre>

<p>Could someone explain me why? What is the correct way of doing this?</p>

<p><a href="http://jsfiddle.net/CV4pU/" rel="nofollow">jsFiddle</a></p>

<p><a href="http://api.jquery.com/add/" rel="nofollow">add() jquery's method</a></p>

<p><strong>EDIT</strong></p>

<p>Finally, this is expected behaviour as all of you pointed it. This is in fact correct to keep matched set unchanged. It's like using value not reference to the set of matched objects.</p>
