Every time I check a checkbox the value gets pushed into an array and I want to append it to a div but each item should be in it's own div.
$(document).ready(function() {
$('input[name="size"]').on('click', function() {
var size = $(this).val();
$('.selected-sizes').empty();
var selectedSize = new Array();
$('input[name="size"]:checked').each(function() {
selectedSize(this.value);
$('.selected-sizes').append('<div class="size-chosen"><span>' + selectedSize + '</span></div>');
});
});
});
But this code I have adds the entire array onto each new line.
small
small, large
small, large, medium
Is it possible to put each item in the array on its own Line like:
small
large
medium
If I put the append outside of the each loop then it shows each item separated by a comma on the same line instead of each on a new line/in own div.
Current outputted html:
<div class="selected-sizes">
<div class="size-chosen"><span>small, large, medium</span></div>
</div>
Required output:
<div class="selected-sizes">
<div class="size-chosen"><span>small</span></div>
</div>
<div class="selected-sizes">
<div class="size-chosen"><span>large</span></div>
</div>
<div class="selected-sizes">
<div class="size-chosen"><span>medium</span></div>
</div>