jQuery variable and object caching
<p>This is something that has been bugging me some time and every time I found myself using different solution for this.</p>

<p>So, I have link in my document which on click creates new element with some ID.</p>

<pre><code>&lt;a href="#" id="test-link"&gt;Link&lt;/a&gt;
</code></pre>

<p>For the purpose of easier reusing, I would like to store that new elements ID in a variable which is jQuery object</p>

<pre><code>var test = $('#test');
</code></pre>

<p>On click I append that new element on body, new element is DIV</p>

<pre><code>$('body').append('&lt;div id="test"/&gt;');
</code></pre>

<p>And here goes the main "problem" - if I test this new elements length with <em>test.length</em> it first returns 0 and later 1. But, when I test it with <em>$('#test').length</em> it returns 1 from the start.</p>

<p>I suppose it is some caching mechanism and I was wondering is there better, all-around solution which will allow to store elements in variables in the start for later repurpose and in the same time work with dynamically created elements.</p>

<p>Live, delegate, something else? What I do sometimes is create string and add it to jQuery object but I think this is just avoiding the real issue. Also, using .find() inside another jQuery object.</p>

<p>Thanks in advance.</p>
