1

I have a table with each row containing a checkbox as well as some other cells. To make the entire row clickable so that it can be used to toggle the state of the checkbox I used this piece of code:

  $('#eoiTable tr').click(function(){
     var $checkbox = $(this).find('input[type=checkbox]');
     $checkbox.prop('checked', !$checkbox.is(':checked'));
  });

This works great for all cells in the row, except when I click directly on the checkbox itself. It re-toggles to its old state. I can understand what's going on here, but how I can make sure that the table onclick event doesn't work when you click on the checkbox itself?

Thanks a ton!

0

2 Answers 2

2

try adding something to stop the event from bubbling

$('#eoiTable tr input[type="checkbox"]').click(function(e) {
   e.stopPropagation();
});

edit: had the wrong type

Sign up to request clarification or add additional context in comments.

Comments

0

You are selecting the row of the table which contain checkbox also. So to avoid the table onclick event fire when checkbox is checked exclude it from the selection like

$('#eoiTable tr + #eoiTable tr input:not("[type=checkbox]")')

not sure about this but try this method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.