Descendents of a table row
<p>I have a table with several rows containing several cells of form inputs (see HTML snippet below). I have a function that removes and individual rows and I'm trying to reindex all of those that remain by iterating over each row (to get the new row index) and, within that, iterating over each input (<code>$('td input', $row).each( ... )</code>) and updating the <code>name</code> and <code>id</code> attributes.  What I'm finding is that the inputs in the first cell get reindexed, but not the cost input in the second cell.</p>

<p>Any idea what I'm missing that's keeping that second cell from getting updated?</p>

<p>Thanks.</p>

<p>HTML Snippet:</p>

<pre><code>&lt;tbody&gt;
  &lt;tr&gt;
    &lt;td&gt;
      &lt;input type="hidden" name="data[Ticket][0][id]" value="" id="Ticket0Id"&gt;       
      &lt;input type="hidden" name="data[Ticket][0][date_id]" value="" id="Ticket0DateId"&gt;            
      &lt;input name="data[Ticket][0][name]" type="text" maxlength="45" value="" id="Ticket0Name"&gt;          
    &lt;/td&gt;
    &lt;td&gt;
      &lt;input name="data[Ticket][0][cost]" type="text" value="" id="Ticket0Cost"&gt;         
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;
      &lt;input type="hidden" name="data[Ticket][1][id]" value="" id="Ticket1Id"&gt;            
      &lt;input type="hidden" name="data[Ticket][1][date_id]" value="" id="Ticket1DateId"&gt;            
      &lt;input name="data[Ticket][1][name]" type="text" maxlength="45" value="" id="Ticket1Name"&gt;          
    &lt;/td&gt;
    &lt;td&gt;
      &lt;input name="data[Ticket][1][cost]" type="text" value="" id="Ticket1Cost"&gt;          
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
</code></pre>

<p>By popular demand, here's the jQuery snippet that attempts to do the reindexing:</p>

<pre><code>// $tbody references the &lt;tbody&gt; element in the snippet above
$('tr', $tbody).each( function( i, row ) {
  var $row = $(row);

  $('td input', $row).each( function( j, input ) {
    $(input).attr( 'id', $(this).attr( 'id' ).replace( /\d+/g, i ) )
    $(input).attr( 'name', $(this).attr( 'name' ).replace( /\d+/g, i ) );
  })
});
</code></pre>
