I'm playing around with DataTables and I have a table like this :
<table id='dt'>
<thead><!-- Some Header --></thead>
<tbody>
<tr data-lineid=1>
<td><input type='checkbox' class='checked_entry' id='checked_1'></td>
<td>Column 1</td>
<td>Column 2</td>
</tr>
<!-- Rest of the table -->
</tbody>
</table>
What I am trying to do is to be able to click everywhere in the row, and it will select the checkbox of this row :
$('#dt tbody').on('click', 'tr', function() {
var id = $(this).data('lineid');
if ($('#checked_'+id).prop('checked')) {
$('#checked_'+id).prop('checked', false);
} else {
$('#checked_'+id).prop('checked', true);
}
});
This is working fine, except that now, when I'm clicking on the checkbox itself, it seems it triggers the checkbox click event plus the event bound on the tr.
I've tried something like :
$('#dt tbody').on('click', 'tr :not(input)', function() { ... });
But this seems not to work.
Could anyone give me a tip on this please ?
Thanks !