Show in div or p which checkboxes were checked

I want to show in the div which checkboxes were checked

eg

<input id="checkbox1" type="checkbox"><label for="checkbox1">Checkbox 1</label>

<p>you have selected:</p> <div>checkbox 1</div>

the “More than 1” checkbox will appear (37) and I need it so that it can select all the checkboxes

I think the point

thanks

+4
source share
2 answers

Here's how I do it:

$("input[type='checkbox']").change(function(){
    $("#checked").empty();
    $("input[type='checkbox']:checked").each(function(){
        $("#checked").html($("#checked").html() + $(this).next().text() + "<br/>");
    });
});

Here is the JSFiddle daemon

+1
source

You can use:

$(":checkbox").change(function(){
   $('div').html($(':checked').map(function(){
      return $(this).next().text()
   }).get().join(','));
});

Working demo

+6
source

Source: https://habr.com/ru/post/1606548/


All Articles