add  array keys with span tags
<p>i have an array like:</p>

<pre><code>var totalNum = new Array('img', 'img', 'img', 'img');
</code></pre>

<p>now on the <code>documentready</code> i added a <code>div</code> in the html page like:</p>

<pre><code>$('#mainid').after('&lt;div id="button"&gt;&lt;/div&gt;');
</code></pre>

<p>the problem is i want to add <code>&lt;span&gt;&lt;/span&gt;</code> tags with total numbers in <code>totalNum</code> array like:</p>

<pre><code>&lt;div id="button"&gt;
   &lt;span&gt;1&lt;/span&gt;
   &lt;span&gt;2&lt;/span&gt;
   &lt;span&gt;3&lt;/span&gt;
   &lt;span&gt;4&lt;/span&gt;
&lt;/div&gt;
</code></pre>

<p>i tried with <code>for(){}</code> loop into the <code>.after()</code> but got the syntax error. My code is here:</p>

<pre><code>jQuery('#mainid').after('&lt;div id="button"&gt;' + 
        for(i=1;i&lt;=totalNum.length;i++){
    jQuery('&lt;span&gt;'+i+'&lt;/span&gt;').appendTo('#button');
}
    + '&lt;/div&gt;');
</code></pre>
