I want to loop through an array which was returned as a response from an api call and create elements dynamically with it. This is my code,
$.ajax({
url: "http://localhost:3333/testimonials",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
success: function (response) {
jQuery.each(response, function(index, value){
var item = $("<div class='item'></div>");
var shadowEffect = $("<div class='shadow-effect'></div>");
var testimonialName = $("<div class='testimonial-name'>"+value.name+"</div>");
var review = $("<p></p>").text(value.review);
$("#customers-testimonials").append(item);
$(".item").append(shadowEffect,testimonialName);
$(".shadow-effect").append(review);
});
}
});
I want to create a structure like this dynamically,
<div id="customers-testimonials" class="owl-carousel">
<div class="item">
<div class="shadow-effect">
<img class="img-circle" src="http://themes.audemedia.com/html/goodgrowth/images/testimonial3.jpg" alt="">
<p>Dramatically maintain clicks-and-mortar solutions without functional solutions. Completely synergize resource taxing relationships via premier niche markets. Professionally cultivate.</p>
</div>
<div class="testimonial-name">EMILIANO AQUILANI</div>
</div>
<div class="item">
<div class="shadow-effect">
<img class="img-circle" src="http://themes.audemedia.com/html/goodgrowth/images/testimonial3.jpg" alt="">
<p>Dramatically maintain clicks-and-mortar solutions without functional solutions. Completely synergize resource taxing relationships via premier niche markets. Professionally cultivate.</p>
</div>
<div class="testimonial-name">EMILIANO AQUILANI</div>
</div>
</div>
But here is what i get with my code,
<div id="customers-testimonials" class="owl-carousel">
<div class="item">
<div class="shadow-effect">
<img class="img-circle" src="http://themes.audemedia.com/html/goodgrowth/images/testimonial3.jpg" alt="">
<p>Dramatically maintain clicks-and-mortar solutions without functional solutions. Completely synergize resource taxing relationships via premier niche markets. Professionally cultivate.</p>
</div>
<div class="testimonial-name">EMILIANO AQUILANI</div>
<div class="shadow-effect"> <======= Repeated item
<img class="img-circle" src="http://themes.audemedia.com/html/goodgrowth/images/testimonial3.jpg" alt="">
<p>Dramatically maintain clicks-and-mortar solutions without functional solutions. Completely synergize resource taxing relationships via premier niche markets. Professionally cultivate.</p>
</div>
<div class="testimonial-name">EMILIANO AQUILANI</div> <======= Repeated item
</div>
<div class="item">
<div class="shadow-effect">
<img class="img-circle" src="http://themes.audemedia.com/html/goodgrowth/images/testimonial3.jpg" alt="">
<p>Dramatically maintain clicks-and-mortar solutions without functional solutions. Completely synergize resource taxing relationships via premier niche markets. Professionally cultivate.</p>
</div>
<div class="testimonial-name">EMILIANO AQUILANI</div>
</div>
</div>
How do I resolve it? Any help would be much appreciated Thanks