jquery not working as expected in javascript for loop
<p>I've encountered the problem of using jQuery inside the javascript for loop. After more than 24 hours investigating I've decided to post the core of the problem. I've shrunk the code to the simple example:</p>

<pre><code>var a, i, j;
var n = $("div.kategorija_tekst").length;
document.write("n = " + n + "&lt;br&gt;");
for (i = 0; i &lt; n; i++){
    a = $("div.kategorija_tekst").length;
    document.write("polje["+i+"]  = " + a +"&lt;br&gt;");
    for (j = 0; j &lt; a; j++){
        document.write($("div.def_tekst").eq(j).height() + "px, ");
    }
}
</code></pre>

<p>I've got:</p>

<ul>
<li><p>in Opera 12.14, Google Chome  24.0.1312.57 m, Safari 5.1.7., Firefox 18.0.2: </p>

<blockquote>
  <p>n = 6, polje[0] = 0, polje[1] = 0, polje[2] = 0, polje[3] = 0, polje[4] = 0, polje[5] = 0,</p>
</blockquote></li>
<li><p>in IE8:</p>

<blockquote>
  <p>n = 6</p>
</blockquote></li>
</ul>

<p>But it should be expected as:</p>

<blockquote>
  <p>n = 6, polje[0] = 6, 28px, 28px, polje[1] = 6, 28px, 28px, polje[2] = 6,  28px, 28px, polje[3] = 6, 28px, 28px, polje[4] = 6, 28px, 28px, polje[5] = 6, 28px, 28px,</p>
</blockquote>

<p>Strange! Why has the <code>a</code> variable inside the for loop got zero value? Why are the <code>height()</code> values (in the nested <code>for</code> loop) completely missing? Why IE8 hasn't succeeded to write even this line(s)? </p>

<pre><code>("polje["+i+"]  = " + a + "&lt;br&gt;")
</code></pre>

<p>Any help would be greatly appreciated!</p>
