title: jQuery Replace Table Body Contents
body: <p>I seem to be having problems with my jQuery script. I would like to replace the current "tbody" contents with the new "tbody" contents. Currently it is just continues to add to the current data instead of removing the old data and inserting the new data. Any ideas?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function getData(action,searchVal) {    
      $.get('ajax.php',{action:action,value:searchVal}, function(data){
          var json = jQuery.parseJSON(data);
          $(function () {
              var content = '';
              content += '&lt;tbody&gt;';
              for (var i = 0; i &lt; json.length; i++) {
              content += '&lt;tr id="' + json[i].ID + '"&gt;';
              content += '&lt;td&gt;&lt;input id="check_' + json[i].ID + '" name="check_' + json[i].ID + '" type="checkbox" value="' + json[i].ID + '" autocomplete=OFF /&gt;&lt;/td&gt;';
              content += '&lt;td&gt;' + json[i].ID + '&lt;/td&gt;';
              content += '&lt;td&gt;' + json[i].Name + '&lt;/td&gt;';
              content += '&lt;td&gt;' + json[i].CountryCode + '&lt;/td&gt;';
              content += '&lt;td&gt;' + json[i].District + '&lt;/td&gt;';
              content += '&lt;td&gt;' + json[i].Population + '&lt;/td&gt;';
              content += '&lt;td&gt;&lt;a href="#" class="edit"&gt;Edit&lt;/a&gt; &lt;a href="#" class="delete"&gt;Delete&lt;/a&gt;&lt;/td&gt;';
              content += '&lt;/tr&gt;';
              }
              content += '&lt;/tbody&gt;';
              $('table tbody').replaceWith(content);  
         });  
      });
  };
  </code></pre>