mercredi 13 janvier 2016

How can I add items to a list when a checkbox is checked in jQuery?

I have a list of checkbox and I want that when it's checked, the label or the value of the checkbox will be added in a list.

The fiddle below, when the checkbox is checked/unchecked, it adds 'on' to the list.

Here's a sample fiddle

$('.cb').click(function() {
  var cbVal = $("input[type='checkbox']").val();
  $('ul').append('<li>'+cbVal+'</li>')
});




Aucun commentaire:

Enregistrer un commentaire