This answer does not treat the switches as checkboxes (users really don't like it) and try to create a slightly more realistic script.
$("tr.myRow").click(function(e) { // dont override the radio inputs default if ($(e.target).hasClass("childRadio") || e.target.tagName == 'LABEL') return; // find the child radio, and if it not checked, check it. var $childRadio = $("input.childRadio", $(this)); if (!$childRadio.attr('checked')) { $childRadio.attr('checked', 'checked'); } });
I ran into the problem of adding labels and used the name property so that the switches are grouped (which is the reason for the presence of the switches). Thus, this preserves the maximum possible behavior by default and simply increases clicks to select a specific child radio button.
Below is an example html.
<tr class="myRow"> <td> <div>Some Content</div> <div> <label for="radio1">Radio 1 Label</label> <input type='radio' id="radio1" class="childRadio" checked="checked" name="Group1"> </div> <div>More Content</div> </td> </tr> <tr class="myRow"> <td> <div> <label for="radio2">Radio 2 Label</label> <input type='radio' id="radio2" class="childRadio" name="Group1"> </div> </td> </tr>
Robert Paulson
source share