Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a workaround, as radiobutton.click() hangs Safari but works in Chrome

I have a table with some checkboxes in it, and I've added this code so that when you click on any part of specific table cells, the checkbox is checked. When a checkbox is checked, I need to remove a disabled class from a button in order to allow the user to move to the next step.

This code works fine in Chrome, but in Safari it hangs the window, immediately when $('input:radio', $parent).click() is called.

Is there a more correct way to be doing this?

$('td.info, td.control').click(function() {
  var $parent;
  $parent = $(this).parent();
  $('input:radio', $parent).attr('checked', true);
  return $('input:radio', $parent).click();
});
$("input[name='package[order_option_id]']").click(function() {
  return ($("#select-interaction-link")).removeClass('disabled');
});
like image 294
Tim Sullivan Avatar asked Nov 19 '25 17:11

Tim Sullivan


1 Answers

I think the reason for the hang is that you're causing an infinite loop. When the code clicks on the radio button, the click bubbles up to the containing td, which causes your click() handler to be run again.

I think you can solve this with:

$("td.info input:radio, td.control input.radio").click(function(e) {
    e.stopPropagation();
}
like image 75
Barmar Avatar answered Nov 22 '25 07:11

Barmar



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!