I have an array:
var bar = [];
I have a for loop going through the array:
for (var i = 0; i <= 3; i++) {
$(".left-lg").find(".name").html(bar[i].name);
}
I am trying to replace the content of the DIV.name with the content in the array, it works but only gives me the last one in the array. I read, on a click event with javascript the loop will be at the end, so that is why.
Any way how to correct this so it will go through the entire loop and not just give the last one?
That’s because you’re always setting the HTML content of all the elements matching
.name. Try using theindexargument supplied to each() instead: