I have this check box:
<div class="OuterDiv">
<div class="InnerDiv">
<input type="checkbox" name="tie" value="tie">Error in tie score<br>
</div>
</div>
I have this jquery to toggle the checkbox:
$(document).ready(function() {
$('.OuterDiv').click(function() {
if ($(this).find('input:checkbox').is(':checked')) {
$(this).find('input:checkbox').attr('checked',false);
} else {
$(this).find('input:checkbox').attr('checked',true);
}
});
});
This seems to work, to toggling the checkbox when clicking on the div. However when I click the checkbox itself, nothing happens and it does not toggle.
<label>around the checkbox?.prop()rather than.attr().label. Its there for a reason. Also, When you click the checkbox, it checks the checkbox (the default functionality), but the event is propagated toOuterdivand thus your function toggles it and you see no change