Checkbox add to list jquery
How to add items to a list when a checkbox is checked in jQuery?
by ionutbradean
HTML
<fieldset class="fieldset">
<legend>Ingredients</legend>
<input id="checkbox12" value="Apple" class="cb" type="checkbox">
<label for="checkbox12">Apple</label>
<input id="checkbox22" value="Orange" class="cb" type="checkbox">
<label for="checkbox22">Orange</label>
<input id="checkbox32" value="Cinnamon" class="cb" type="checkbox">
<label for="checkbox32">Cinnamon</label>
</fieldset>
<h4>Lists:</h4>
<ul>
</ul>
JavaScript
$('.cb').click(function() {
$('ul').html("");
$(".cb").each(function(){
if($(this).is(":checked")){
$('ul').append('<li>'+$(this).val()+'</li>')
}
});
});