JSFiddle - React, Tailwind, and code Playground

by Ketan Patel

HTML

<div>
    <input type="checkbox" checked="checked" name="options[]" value="1" />
    <input type="checkbox" name="options[]" value="2" />
    <input type="checkbox" name="options[]" value="3" />
    <input type="checkbox" checked="checked" name="options[]" value="4" />
    <input type="checkbox" name="options[]" value="5" />
</div>
<span></span>

JavaScript

function calculate() {

    var arr = $.map($('input:checkbox:checked'), function(e, i) {
        return +e.value;
    });

    $('span').text('the checked values are: ' + arr.join(','));
}

calculate();

$('div').delegate('input:checkbox', 'click', calculate);