This is the html:
<div class="btn btn-stock-report" id="superman">
Superman <input type="checkbox" name="superman" />
</div>
this is the JQuery:
$('#superman').on('click', function () {
if ($(this).children('input:checkbox:first').is(':checked')) {
superman = true;
$(this).children('input:checkbox:first').removeAttr('checked');
}
else {
superman = false;
$(this).children('input:checkbox:first').attr('checked', 'checked');
}
console.log("superman: " + superman);
});
What I'm trying to achieve it simply change the state of the child checkbox and change the value of a superman
variable, but for some reason it always prints out superman: false
in the console log. Even when I manually check the checkbox and click the div, even though the checkbox is now checked, it reports superman: false
What could be causing this?