issue of race condition b/w direct code and jquery handlers in client side JS
<p>Is this code valid/correct</p>

<pre><code>var items = $(".items");    // when would items be properly populated, at dom.ready()??
var itemsHrefs = []; // direct JS code

prepareItemsList();  **// direct JS code**

**// could be the case that items array is not populated yet ???**
function prepareItemsList() {
  for ( var i = 0; i &lt; items.length; i++ ) {
    var plElement = items.eq(i);
    itemsHrefs.push (plElement.attr('href'));
  }
}
</code></pre>

<p>Questions:</p>

<ol>
<li>When would items variable be properly created. I assume dom.ready()??</li>
<li>Should I put execution of prepareItemsList() inside a document.ready handler to be correct?</li>
</ol>

<p>NOTE: When I tried doing 2. above, I ran into different issues</p>
