I have a data table and I have one checkbox in a row for the user to select an item.
I use the following jQuery code to let the user select an item by clicking anywhere on the line:
$("tbody tr").click(function() { var checkbox = $(this).find(':checkbox'); checkbox.attr('checked', !checkbox.attr('checked')); });
The problem is that I click directly on the checkbox, nothing happens. i.e. if unchecked, it remains unchecked. If I clicked anywhere in the row, the checkbox will change the status.
I think jQuery code causes the action to execute twice. If I click on this flag, this flag will change, and then jQuery code will be executed to click on the line, and the flag will be changed. Not sure if this is really happening, but this is my hunch.
How can I check the box when the user clicks on the line and the same if they click directly on the checkbox?
source share