title: Calculations in JQuery Addition vs. Subtraction
body: <p>Can anybody help me to alter this JQuery code so that it will do a subtraction calculation rather than addition?</p>
  
  <p>In this current code the first table is just a normal table holding the data, the second table is filled dynamically with jQuery adding up the columns. I am not sure how to accomplish the same functionality only doing subtraction down the column. I tried replacing += by -= and it still add the values but places a minus sign in front of them. For example the age column the values for age are 500, 100, 100 and -700 is returned.</p>
  
  <p>Can anybody lend any insight?</p>
  
  <pre><code> &lt;html&gt; 
   &lt;head&gt; 
   &lt;script type="text/javascript" SRC="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"&gt;&lt;/script&gt; 
  
   &lt;/head&gt; 
   &lt;TABLE class=custom id=data&gt; 
   &lt;TBODY&gt; 
   &lt;TR&gt; 
    &lt;TH&gt;name&lt;/TH&gt; 
    &lt;TH&gt;age&lt;/TH&gt; 
    &lt;TH&gt;weight&lt;/TH&gt; 
    &lt;TH&gt;benchpress&lt;/TH&gt; 
   &lt;/TR&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;stan&lt;/TD&gt; 
    &lt;TD&gt;500&lt;/TD&gt; 
    &lt;TD&gt;400&lt;/TD&gt; 
    &lt;TD&gt;300&lt;/TD&gt; 
   &lt;/TR&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;rj&lt;/TD&gt; 
    &lt;TD&gt;100&lt;/TD&gt; 
    &lt;TD&gt;50&lt;/TD&gt; 
    &lt;TD&gt;50&lt;/TD&gt; 
   &lt;/TR&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;jose&lt;/TD&gt; 
    &lt;TD&gt;100&lt;/TD&gt; 
    &lt;TD&gt;50&lt;/TD&gt; 
    &lt;TD&gt;50&lt;/TD&gt; 
   &lt;/TR&gt; 
  &lt;/TBODY&gt; 
  &lt;/TABLE&gt; 
  &lt;BR&gt; 
  &lt;TABLE class=custom&gt; 
  &lt;TBODY&gt; 
  &lt;TR&gt; 
   &lt;TH&gt;ages&lt;/TH&gt; 
   &lt;TH&gt;weights&lt;/TH&gt; 
   &lt;TH&gt;benchpresses&lt;/TH&gt; 
  &lt;/TR&gt; 
  &lt;TR&gt; 
   &lt;TD id=ages&gt;&amp;nbsp;&lt;/TD&gt; 
   &lt;TD id=weights&gt;&amp;nbsp;&lt;/TD&gt; 
   &lt;TD id=benchpresses&gt;&amp;nbsp;&lt;/TD&gt; 
  &lt;/TR&gt; 
  &lt;/TBODY&gt; 
  &lt;/TABLE&gt; 
  &lt;script type="text/javascript"&gt;   
  
  //these will hold the totals 
  var ages = 0; 
  var weights = 0; 
  var benchpresses = 0; 
  
  //reference the rows you want to add 
  //this will not include the header row 
  var rows = $("#data tr:gt(0)"); 
  rows.children("td:nth-child(2)").each(function() { 
  //each time we add the cell to the total 
  ages -= parseInt($(this).text(),10); 
  }); 
  rows.children("td:nth-child(3)").each(function() { 
  weights -= parseInt($(this).text(),10); 
  }); 
  rows.children("td:nth-child(4)").each(function() { 
  benchpresses -= parseInt($(this).text(),10); 
  }); 
  
  //then output them to the elements 
  $("#ages").html(ages); 
  $("#weights").html(weights); 
  $("#benchpresses").html(benchpresses); 
  
  &lt;/script&gt; 
  &lt;/html&gt; 
  </code></pre>