<ul id="list">
</ul>
<input type="checkbox" id="item1" name="item one" />
<input type="checkbox" id="item2" name="item two" />
<input type="checkbox" id="item3" name="item three" />
<input type="checkbox" id="item4" name="item four" />
I need to add checked items to the #list as li's in this format:
<li class="CHECKBOX ID">CHECKBOX NAME</li>
Here's what I'm currently working on:
$('input[type=checkbox]').change(function () {
if($(this).is(':checked')){
var checkboxId = $(this).attr('id');
var checkboxName = $(this).attr('name');
$('#list').append('<li class="' + checkboxId + '">' + checkboxName + '</li>');
} else {
$('#list .' + checkboxId).remove();
}
When ever I work with javascript I always feel like I'm very inefficient. This also doesn't take into account boxes already set to check on page load...