I have an unordered list of text items with checkboxes beside each of them. I want to perform the same function both when a checkbox is checked/unchecked and when the text is clicked.
Here's what I have right now:
The HTML
<li><input type="checkbox" class="cbox" name="adwords_list[]" value="shave club" ><p class="term"> shave club</p></li>
The JS
$(function() {
$('ol.phrases li .term').click(function() {
$cboxStatus = $(this).parent().find('.cbox').prop('checked');
if ($cboxStatus) {
$(this).parent().find('.cbox').prop('checked', false);
} else {
$(this).parent().find('.cbox').prop('checked', true);
}
});
});
$(':checkbox, .term').on('change', function() {
console.log($(this).prop('checked'));
});
The on.change function isn't calling when the term is clicked. What can I do to get an accurate representation of the checked state no matter what element is clicked/changed?
<li><label><input type="checkbox" class="cbox" name="adwords_list[]" value="shave club" > shave club</label></li>labelinstead of thatp. If you successfully pair it with theinput, it will actually change the checkbox.