I am generating multiple checkboxes using ajax call and I want to toggle the checkbox value from 0 to 1 and vice versa. Here 0 is the unchecked state and 1 is the checked state. Tried a couple of ways but could not achieve it.
<div class="form-group">
<label class="control-label col-sm-2" for="department">Departments:</label>
<div class="col-sm-10" id="department">
<!--- Here goes the ajax generated checkboxes. The 1 and 0 is a boolean value coming out of database-->
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="car" name="car" checked="checked" value="1">
<label class="form-check-label col-sm-2" for="car">Finishing</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="bike" name="bike" value="0">
<label class="form-check-label col-sm-2" for="bike">Assembly</label>
</div>
</div>
</div>
Update: I am using something like this just to access check if the checkbox once checked spits out true to the console and it doesn't work.
$( "input" ).change(function() { var $input = $( this ); console.log($input.is( "checked" )); }).change();