title: Iterating through table cells using jquery
body: <p>I have a table containing a variable number of columns.  I wrote a function to iterate through each cell in each row to do the following:</p>
  
  <ol>
  <li>Check for the presence of an input</li>
  <li>Retrieve the value of the input</li>
  <li>Append a pie chart to any cell where condition #1 evaluates to true</li>
  </ol>
  
  <p>Here's my code:</p>
  
  <pre><code>function addPieCharts() {
  var htmlPre = "&lt;span class='inlinesparkline' values='";
  var htmlPost = "'&gt;&lt;/span&gt;"
  var colors = ["red", "blue"];
  
  $("#MarketsTable tr").each(function () {
  
      $('td').each(function () {
          var value = $(this).find(":input").val();
          var values = 100 - value + ', ' + value;
  
          if (value &gt; 0) {
              $(this).append(htmlPre + values + htmlPost);
          }
       })
  
  })
  
  $('.inlinesparkline').sparkline('html', { type: 'pie', sliceColors: colors });
  }
  </code></pre>
  
  <p>Steps 1-3 are basically working as described.  When this runs the pie charts are added to the correct cells displaying the correct values.  My problem is that I'm expecting just one pie chart per cell where there exists an input.  However, I have n pie charts per cell where n is equal to the number of columns in the table.  I suspect I'm using jQuery's each() method incorrectly.  Can someone tell me what I've done wrong?</p>