Looping and setting name and id in jquery
<p>I have created a method to dynamically add rows to a table . each table tow contains two text fields(collectionText and Link)</p>

<pre><code>&lt;tr&gt;
&lt;td&gt;
  &lt;input type="text" size="30" id="txtCollectionText" name="txtCollectionText" /&gt;
&lt;/td&gt;
 &lt;td&gt;
 &lt;input type="text" size="30" id="txtLink" name="txtLink" /&gt;
 &lt;/td&gt;
&lt;/tr&gt; 
</code></pre>

<p>the bellow is my script</p>

<pre><code>   function addRow() {
            var row = $('#table tbody&gt;tr:last').clone(true).insertAfter('#table tbody&gt;tr:last');
            var index = $("#table tbody&gt;tr").length;
            $("td:eq(0)", row).text(index);
            $("td:eq(1) input", row).attr("name", "txtCollectionText" + index).attr("id", "txtCollectionText" + index)
            $("td:eq(2) input", row).attr("name", "txtLink" + index).attr("id", "txtLink" + index)
        }
</code></pre>

<p>This will add the index to newly added  inputs.but not to the existing ones . my requirement the indexes should start form zero .
for example if i have 2 rows by  default ,adding third row will give me collectiontext4 and link4 , but i want numbering for all my rows starting from 0 -4  ...any ideas ??</p>
