jquery wrap div around each iteration of loop
This code takes data from a php file which is doing a json_encode, which is pulling info from a csv file.  I would like a parent div around each group of values within the second loop.  I tried this with the newDiv2, but it wrapped each .field with .sub_row.

Instead of this:

     <div class="row">
         <div class="sum_field">Total: 100.01</div>
         <div class="field">11111</div>
         <div class="field">11111</div>
         <div class="field">22222</div>
         <div class="field">22222</div>
    </div>

It should be this:
     
     <div class="row">
         <div class="sum_field">Total: 100.00</div>
         <div class="sub_row">
              <div class="field">11111</div>
              <div class="field">11111</div>
         </div>
    </div>
     <div class="row">
         <div class="sum_field">Total: 2487.01</div>
      <div class="sub_row">
         <div class="field">11111</div>
         <div class="field">11111</div>
     </div>
     <div class="sub_row">
         <div class="field">22222</div>
         <div class="field">22222</div>
     <div class="sub_row">
    </div>

PHP Code

     $(document).ready(function() {
     $.getJSON('WF-XML.php', function(data) {

        //JSON.stringify(data); 
        var prevCardCode = '';
        var newDiv;

        $.each(data, function(index, element) {
            if (element['CardCode'] != prevCardCode) {
                newDiv = $('<div/>').addClass('row').appendTo('#showdata');
                $('<div class="sum_field">' + 'Total: ' + element['payment_sum'] + '</div>').appendTo(newDiv);		
				}
            prevCardCode = element['CardCode'];
		 
            $.each(element, function(key, value) {
				
                switch (key) {
                    case 'InvKey':
                    case 'PostDate':
                    case 'City':
                    break;

                    default:
		            //newDiv2 = $('<div/>').addClass('sub_row').appendTo('.row');
                    $('<div class="field">' + value + '</div>').appendTo(newDiv);
                    break;
                     }
                 });
             });
         });
      });
 
jquery wrap div around each iteration of loop
===

This code takes data from a php file which is doing a json_encode, which is pulling info from a csv file.  I would like a parent div around each group of values within the second loop.  I tried this with the newDiv2, but it wrapped each .field with .sub_row.

Instead of this:

     <div class="row">
         <div class="sum_field">Total: 100.01</div>
         <div class="field">11111</div>
         <div class="field">11111</div>
         <div class="field">22222</div>
         <div class="field">22222</div>
    </div>

It should be this:
     
     <div class="row">
         <div class="sum_field">Total: 100.00</div>
         <div class="sub_row">
              <div class="field">11111</div>
              <div class="field">11111</div>
         </div>
    </div>
     <div class="row">
         <div class="sum_field">Total: 2487.01</div>
      <div class="sub_row">
         <div class="field">11111</div>
         <div class="field">11111</div>
     </div>
     <div class="sub_row">
         <div class="field">22222</div>
         <div class="field">22222</div>
     <div class="sub_row">
    </div>

PHP Code

     $(document).ready(function() {
     $.getJSON('WF-XML.php', function(data) {

        //JSON.stringify(data); 
        var prevCardCode = '';
        var newDiv;

        $.each(data, function(index, element) {
            if (element['CardCode'] != prevCardCode) {
                newDiv = $('<div/>').addClass('row').appendTo('#showdata');
                $('<div class="sum_field">' + 'Total: ' + element['payment_sum'] + '</div>').appendTo(newDiv);		
				}
            prevCardCode = element['CardCode'];
		 
            $.each(element, function(key, value) {
				
                switch (key) {
                    case 'InvKey':
                    case 'PostDate':
                    case 'City':
                    break;

                    default:
		            //newDiv2 = $('<div/>').addClass('sub_row').appendTo('.row');
                    $('<div class="field">' + value + '</div>').appendTo(newDiv);
                    break;
                     }
                 });
             });
         });
      });
 