Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table Row onClick Overriding Checkbox

I'm having some issues with checkboxes in a table being "overridden" by the onClick attribute of the table row they are placed in.

I have a column with checkboxes as the leftmost column of a table, and I also have an onClick function defined for each table row. As a result, when I click any of the checkboxes, the onClick function of the table row triggers (though the checkbox is still clicked correctly).

Is there any way I can work around this? Having the table row's onClick only register for the other columns, for example? (I have no clue how the implementation of that would work, unfortunately, but that's the first solution I can think of.)

Thanks in advance!

like image 785
sichinumi Avatar asked Dec 11 '25 09:12

sichinumi


2 Answers

Take a look at event.stopPropagation()

event.stopPropagation

You'll want to call this in your checkbox click handler.

like image 122
Mike C Avatar answered Dec 12 '25 23:12

Mike C


$('.columnClass').click(function(e){
     if(this == e.target){
      //do things
 }

})

This will only execute your click handler when it's actually the column that's being clicked, not the checkbox.

like image 25
OldDrunkenSailor Avatar answered Dec 12 '25 21:12

OldDrunkenSailor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!