javascript - Display dynamic number of Divs inside another Div using Jquery -
i have developed following javascript code,
for (var x = 0; x < address.length; x++) { var dynamic_address = "<div class='col-lg-6 col-md-6 col-sm-6 col-xs-12 mob-no-pad'>" + "<div class='address-blk'><span>1</span><p class='store-name'>" + storename[x] + ",</p>" + "<address>" + address[x] + "</address>" + "<p>sent : <a href=''>email</a> | <a href=''>text</a> | <a href=''>get directions</a></p> </div></div>"; $("#location-address").html(dynamic_address); } <div id="location-address"></div> my question when run code final address of address array , final value of storename array displayed in location-address div (only 1 div). address.length has dynamic value. how can display three(any number) divs, not 1 div?
the issue because you're using html() method overwrite previous value in element, hence last element of loop shown. need use append() instead:
$("#location-address").append(dynamic_address); if needed, may need use empty() clear content of #location-address before running through loop update content.
Comments
Post a Comment