Sum of numbers from dynamic inner text using jquery
<p>I would like to get the total sum of values having class addition1:::</p>

<p>HTML CODE is</p>

<pre><code>&lt;tr &gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;Total Inr&lt;/td&gt;
  &lt;td align="right" class="heading"&gt;&lt;?php if($inr!='')echo co($inr);else echo "0.00";?&gt;     &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;ROE&lt;/td&gt;
  &lt;td  class="heading" &gt;&lt;span class="addition1"&gt;&lt;?php if($inr!='')echo co($inr);else echo "0.00";?&gt; &lt;/span&gt;   &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;Total Usd&lt;/td&gt;
  &lt;td align="right" class="heading"&gt;&lt;?php if($usd!='')echo co($usd);else echo "0.00";?&gt; &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /&gt;&lt;/td&gt;
  &lt;td class="heading1"  style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;"&gt;
    &lt;span class="addition1"&gt;
            &lt;?php if($usd!='')echo co($usd);else echo "0.00";?&gt;  &lt;/span&gt;  
  &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;Total Gbp&lt;/td&gt;
  &lt;td align="right" class="heading"&gt;&lt;?php if($gbp!='')echo co($gbp);else echo "0.00";?&gt;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /&gt;&lt;/td&gt;
  &lt;td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;"&gt;
    &lt;span class="addition1"&gt;&lt;?php if($gbp!='')echo co($gbp);else echo "0.00";?&gt;&lt;/span&gt;
  &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;Total Eur&lt;/td&gt;
  &lt;td align="right" class="heading"&gt;&lt;?php if($eur!='')echo co($eur); else echo "0.00";?&gt;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input name="roe1" id="roe13"  type="text" class="heading" value="1" style="width:50px" /&gt;&lt;/td&gt;
  &lt;td  class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;"&gt;
   &lt;span class="addition1"&gt; &lt;?php if($eur!='')echo co($eur); else echo "0.00";?&gt;&lt;/span&gt;
  &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="heading"&gt;Total Other&lt;/td&gt;
  &lt;td align="right" class="heading"&gt;&lt;?php if($other!='')echo co($other);else echo "0.00";?&gt;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /&gt;&lt;/td&gt;
  &lt;td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;"&gt;
    &lt;span class="addition1"&gt;&lt;?php if($other!='')echo (co($other));else echo "0.00";?&gt;    &lt;/span&gt;
  &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>Jquery Code is</p>

<pre><code>    $(document).ready(function() {
    $('#tables tbody&gt;tr&gt;td&gt;input.heading#roe13').change(function() {
        var k = $('#roe13').val(); 
         $('#tables tbody&gt;tr&gt;td.heading3').text(function(i,v) {
            v= v.replace(/,/g, ''),
            asANumber = +v;
            x=Math.round(parseFloat(v*k)*100) / 100;
            return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");

        });
    });


$('#tables tbody&gt;tr&gt;td&gt;input.heading#roe11').change(function() {
        var k = $('#roe11').val(); 
        $('#tables tbody&gt;tr&gt;td.heading1').text(function(i,v) {
            v= v.replace(/,/g, ''),
            asANumber = +v;                 
            x1=Math.round(parseFloat(v*k)*100) / 100;
            return x1.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
        });
    });

$('#tables tbody&gt;tr&gt;td&gt;input.heading#roe12').change(function() {
        var k = $('#roe12').val(); 
        $('#tables tbody&gt;tr&gt;td.heading2').text(function(i,v) {
            v= v.replace(/,/g, ''),
            asANumber = +v;                 
            x2=Math.round(parseFloat(v*k)*100) / 100;
            return x2.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
        });
    });

$('#tables tbody&gt;tr&gt;td&gt;input.heading#roe14').change(function() {
        var k = $('#roe14').val(); 
        $('#tables tbody&gt;tr&gt;td.heading4').text(function(i,v) {
            v= v.replace(/,/g, ''),
            asANumber = +v;                 
            x3=Math.round(parseFloat(v*k)*100) / 100;
            return x3.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
        });
    });


$('#tables tbody&gt;tr').change(function() {
        var sum = 0;
        var regex = /\((\d+)\)/g;
        $('span.addition1').each(function() {       
            matches = $(this).text().replace(/,/g, ''); alert(matches);
            if( !isNaN( matches ) ){        
                sum += parseFloat(matches);
            }           
        });
    }); 
});
</code></pre>

<p>Class name in td can't be changed . I am trying to get the sum of values having class addition1. On running this code, 1 value is getting skipped, e.g. If I change a value say x1 then result generated due to x1 will be skipped in addition.
Please help me out.</p>
