JSFiddle - React, Tailwind, and code Playground
by Santosh Giridhara
HTML
<form id='checkboxes'>
<p><label>Peanuts? <input name='peanuts' type='checkbox'/></label></p>
<p><label>Applejacks? <input name='applejacks' type='checkbox'/></label></p>
</form>
JavaScript
var checkboxes = {};
$("#checkboxes").delegate("input[type='checkbox']", 'change', function() {
var $this = $(this);
//console.log($this.prop('checked'));
if ($this.prop('checked')) {
checkboxes[$this.attr('name')] = $this.val();
} else {
delete checkboxes[$this.attr('name')];
}
console.log(checkboxes);
});