I want to make it so that if you click anywhere inside a table cell, the checkbox in the cell is toggled. It should also work normally if the checkbox is clicked directly.
Here I used a red bordered blank "label" as the clickable area. Ideally I'd like to avoid labels.
<tr>
<td><label><input type="checkbox"/></label></td>
<td><input type="checkbox"/></td>
<td><input type="checkbox"/></td>
</tr>
Here the table cell click is being detected.
$('td').click(function(){
alert('click!');
If false is returned and the checkbox is clicked, the checkbox initially checked and then when you dismiss the alert popup the checkbox clears again. (at least in Chrome, Firefox and IE11)
$('td').click(function(){
alert('click!');
return false;
I tried this with return false and no return. If you click on the cell it works but it doesn't work if you click the checkbox.
var $elem = $(this).find('input');
$elem.prop('checked', !$elem.prop('checked'));
If I do $elem.click() with no return statement it has the same problem.
$elem.click();
If I have "return false" it doesn't work at all:
So basically I want to be able to click anywhere in a cell including directly on the checkbox to toggle the checkboxes.