php - Highlight table row and select radio input when table row clicked jquery -
i'm trying achieve similar : want select radio input , highlight table row when clicks somewhere in table .same idea radio input http://jsfiddle.net/fbhav/2/
can ? should change in jquery?
html :
<table class="record_table"> <tr> <td> <input type="radio" /> </td> <td>hello</td> <td>hello</td> </tr> <tr> <td> <input type="radio" /> </td> <td>hello</td> <td>hello</td> </tr> <tr> <td> <input type="radio" /> </td> <td>hello</td> <td>hello</td> </tr> <tr> <td> <input type="radio" /> </td> <td>hello</td> <td>hello</td> </tr>
jquery :
$(document).ready(function () { $('.record_table tr').click(function (event) { if (event.target.type !== 'radio') { $(':radio', this).trigger('click'); } }); $("input[type='radio']").change(function (e) { if ($(this).is(":checked")) { $(this).closest('tr').addclass("highlight_row"); } else { $(this).closest('tr').removeclass("highlight_row"); } }); });
i think major problem forget group radio buttons, i.e
<input type="radio" name="test" />
then work both when clicking on radio button , <tr>
:
$(document).ready(function () { $('.record_table tr').click(function (event) { if (event.target.type !== 'radio') { $(':radio', this).trigger('click'); } }); $("input[type='radio']").change(function (e) { e.stoppropagation(); $('.record_table tr').removeclass("highlight_row"); if ($(this).is(":checked")) { $(this).closest('tr').addclass("highlight_row"); } }); });
forked fiddle -> http://jsfiddle.net/48o1kycu/
Comments
Post a Comment