jquery - appendTo not working -


good evening,

i have following code

$( document ).ready(function() {     $.get( "php/get_ratings.php")          .done(function(data) {             $("#newrow").html('');             $("#list_loc").html('');             var results = jquery.parsejson(data);              $.each(results, function(i, value) {                 var newrow =   $("<div />", {                     id : "new"+results[i].id                 });                 var newloc = $("<div />", {                     id: "loc"+results[i].id,                     text: results[i].city                 });                 $("#newrow").append(newrow);                 $("#list_loc").append(newloc);                  $('#list_loc').appendto('#newrow');             })         }); }); 

html

<div class="container">    <div class="row list">      <div id="newrow">        <div class="row">           <div class="col-md-12">              <div id="list_loc">              </div>           </div>        </div>      </div>     </div>  </div> 

what trying achieve create 2 dynamic div's , insert 1 div other reason "newrow" div. can please explain doing wrong?

thanks in advance,

d

p.s expecting final html

<div class="list">  <div id="row1">    <div id="loc1">    </div>  <div id="row2">   <div id="loc2">   </div>  </div> </div> 

try this:

$(document).ready(function () {     $.get("php/get_ratings.php")             .done(function (data) {                 $("#newrow").html('');            //   $("#list_loc").html(''); no point, cleared in line above                 var results = jquery.parsejson(data);                  $.each(results, function (i, value) {                     var newrow = $("<div />", {                         id: "new" + results[i].id                     }).append( //new loc appeneded directly new row                             $("<div />",                                     {                                         id: "loc" + results[i].id,                                         text: results[i].city                                     })                             );                      $("#newrow").append(newrow);                 });             }); }); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -