I'm trying to append the values of array I've made into another div but when I append the array value its appending all the values of the array not just the one I've added(by click), any suggestions would be great, thanks in advance!
HTML
<div id="products">
<ul>
<li><p>Lorem 1</p><button class="target">Add</button></li>
<li><p>Lorem 2</p><button class="target">Add</button></li>
</ul>
</div>
<div id="cart">
<ul>
</ul>
</div>
jQuery
$(document).ready(function(){
var array = Array();
$(".target").click(function() {
array.push($(this).siblings('p').text());
$.each(array, function(index, value) {
$("#cart ul").append("<li>"+value+"</li>");
});
});
});
When I click Add on say the first button its displays
Lorem 1
but when I then click the add on the second button it displays
Lorem 1 Lorem 1 Lorem 2