Using Bootstrap 3.3.6, JQuery 1.11.3
I'm having an issue with a small section, specifically regarding selecting and deselecting a checkbox when the user clicks on the row.
jsfiddle here: http://jsfiddle.net/0ogdt9s7/1/
html
<div id="not-working">
<h3>
Click the text, then click the box
</h3>
<div class="selection-row" data-id="20">
<div class="col-md-5">Data 20</div>
<div class="col-md-2">
<input type="checkbox" name="selectedDudes[]" value="20" id="checkbox-20">
</div>
</div>
<div class="selection-row" data-id="22">
<div class="col-md-5">Data 22</div>
<div class="col-md-2">
<input type="checkbox" name="selectedDudes[]" value="22" id="checkbox-22">
</div>
</div>
</div>
js
$(document).ready(function() {
$(document).on("click", "div.selection-row", function() {
var $cb = $('input[type="checkbox"]', $(this)), is_on = $cb.prop('checked');
if (is_on) {
//if its already checked, uncheck it
$cb.prop('checked', false);
} else {
//if its not checked, check it
$cb.prop('checked', true);
}
});
});
The row selection works great, but if you click on the checkbox inside the row, the checkbox does not change. Clicking on 'Data' will change it correctly, but the checkbox is doing nothing.
Important to note:
It must reside inside $(document).on()
because this is inside a popup which is displayed through AJAX.
I'm assuming this is something super simple, but I just cannot find it. Any help is appreciated.