How can I dynamically print to another table with JQuery/Javascript?
<p>I am a beginner in JQuery/Javascript, so I appreciate any help in advance.</p>

<p>I have two scripts/tasks. Using JQuery. the first script parses a file and report its contents in table form. The goal of the second script is to run an analysis and display results in a separate table. 
The first task is successful, however, for the second task, instead of populating the second table, the data appends to the first table. What am I missing here? </p>

<p><code>file.html</code></p>

<pre><code>&lt;section id='results'&gt;
  &lt;p&gt;&lt;span id='program'&gt;no&lt;/span&gt; program used.&lt;/p&gt;
  &lt;p&gt;&lt;span id='match_count'&gt;0&lt;/span&gt; match(es) found.&lt;/p&gt;
  &lt;button name="resubmit" id="resubmit" type="submit"&gt;Save selected results&lt;/button&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;td&gt;Save?&lt;/td&gt;
        &lt;td&gt;DB&lt;/td&gt;
        &lt;td&gt;Accession&lt;/td&gt;
        &lt;td&gt;Description&lt;/td&gt;
        &lt;td&gt;Score&lt;/td&gt;
        &lt;td&gt;E-value&lt;/td&gt;
        &lt;td&gt;Start&lt;/td&gt;
        &lt;td&gt;Stop&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;!-- this will be filled in by javascript when there are results --&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/section&gt;

&lt;section id='dbresults'&gt;
  &lt;p&gt;&lt;span id='db_count'&gt;0&lt;/span&gt; match(es) found.&lt;/p&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;td&gt;Accession&lt;/td&gt;
        &lt;td&gt;Description&lt;/td&gt;
        &lt;td&gt;Structural&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;!-- this will be filled in by javascript when there are results --&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
</code></pre>

<p><code>file.js</code></p>

<pre><code>function processJSON( data ) {
// set the span that lists the match count
$('#match_count').text( data.match_count );
// set the span that lists the program used
$('#program').text( data.program );
var next_row_num = 1;
// iterate over each match and add a row to the result table for each
$.each( data.matches, function(i, item) {
        var this_row_id = 'result_row_' + next_row_num++;
        $('&lt;tr/&gt;', { "id" : this_row_id } ).appendTo('tbody');
        $('&lt;td/&gt;', { "text" : item.database } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.accession } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.description } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.score } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.evalue } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.start } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.stop } ).appendTo('#' + this_row_id);
    });
$('#results').show();
}

function processJSON_db( data ) {
$('#db_count').text( data.db_count );
var next_row_num = 1;
$.each( data.dbmatches, function(i, item) {
        var this_row_id = 'result_row_' + next_row_num++;
        $('&lt;tr/&gt;', { "id" : this_row_id } ).appendTo('tbody');
        $('&lt;td/&gt;', { "text" : item.accession } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.description } ).appendTo('#' + this_row_id);
        $('&lt;td/&gt;', { "text" : item.structural } ).appendTo('#' + this_row_id);
    });
$('#dbresults').show();
}
</code></pre>
