title: Get total from table input as grand total in jquery?
body: <p>I created a simple stock saving table for my project. Also i added a button to add row to my table.this is my table,</p>
  
  <pre><code>                            [add button]
  +---------------+-----------+-----------+
  +   lense type  +   qty     +   total   +
  +---------------+-----------+-----------+
  +               +           +           +
  +---------------+-----------+-----------+
  +               grand total : LKR       +
  +---------------------------------------+
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I added html code of the table,</p>
  
  <pre><code>&lt;table class="table" id="tbl-add-lense"&gt;
              &lt;thead style="background-color:#f5edff;"&gt;
              &lt;th style="width:2%;"&gt;&lt;input type="checkbox" name="chk_in" id="checkall"&gt;&lt;/input&gt;&lt;/th&gt;
              &lt;th style="width:2%;"&gt;item no&lt;/th&gt;
              &lt;th style="width:5%;"&gt;Lense Type&lt;/th&gt;
              &lt;th style="width:5%;"&gt;Unit price&lt;/th&gt;
              &lt;th style="width:5%;"&gt;Quantity&lt;/th&gt;
              &lt;th style="width:5%;"&gt;Total&lt;/th&gt;
          &lt;/thead&gt;
          &lt;tbody id="tbl-lesne-body"&gt;
              &lt;tr id="addr0"&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="chk_in"&gt;&lt;/input&gt;&lt;/td&gt;
                  &lt;td&gt;1&lt;/td&gt; &lt;td&gt;&lt;input name='tb-lense-type1' type='text' placeholder='Lense Type' class='form-control '/&gt; &lt;/td&gt;
                  &lt;td&gt;&lt;input  name='td-lunit1' type='number' placeholder='0'  class='form-control'&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input  name='td-lqty1' type='number' placeholder='0'  class='form-control'&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input  name='tb-ltotal1' type='number' placeholder='00.00'  class='form-control total'&gt;&lt;/td&gt;
  
              &lt;/tr&gt;
  
          &lt;/tbody&gt;
          &lt;tfooter&gt;&lt;/tfooter&gt;
         &lt;/table&gt;
  </code></pre>
  
  <p>This table has one row. I used add button to add more rows. add row button code,</p>
  
  <pre><code>$("#add-lense-row").click(function(){
  
        $("#tbl-lesne-body").append("&lt;tr id='addr"+(i+1)+"'&gt;&lt;td&gt;&lt;input type='checkbox' name='chk_in'&gt;&lt;/input&gt;&lt;/td&gt;&lt;td&gt;"+ (i+1) +"&lt;/td&gt; &lt;td&gt;&lt;input name='tb-lense-type"+i+"' type='text' placeholder='Lense Type' class='form-control '/&gt; &lt;/td&gt; &lt;td&gt;&lt;input  name='td-lunit"+i+"' type='number' placeholder='0'  class='form-control'&gt;&lt;/td&gt;&lt;td&gt;&lt;input  name='td-lqty"+i+"' type='number' placeholder='0'  class='form-control'&gt;&lt;/td&gt;&lt;td class='tot'&gt;&lt;input  name='td-ltotal"+i+"' type='number' placeholder='00.00' class='form-control total'&gt;&lt;/td&gt;&lt;/tr&gt;");
  
        i++; 
  
     });
  </code></pre>
  
  <p>total <code>&lt;td&gt;</code>  has a <code>input</code> ,</p>
  
  <pre><code>&lt;input  name='tb-ltotal1' type='number' placeholder='00.00'  class='form-control total'&gt;
  </code></pre>
  
  <p>I need to get sum of total td inputs when typing on a input. I tried this code,</p>
  
  <pre><code> $(".total").keyup(function(){
              console.log('Typing');
              sum += parseFloat($(this).val()); 
          });
  </code></pre>
  
  <p>but it only working on the first table row. If i add a new row and try this code. It's not working. I removed <code>sum += parseFloat($(this).val());</code>  line and tried. Still code working only in the first row. How to solve this. Thank you</p>