javascript - How to check/uncheck a checkbox while clicking a table row -
i need check/uncheck checkbox exist inside row under table body when clicked anywhere within row except link. tried make working using jquery's prop, not working properly.
i have table structure below:
<table id="anywhere_click"> <thead> <tr> <th><input type="checkbox" onclick="selectall('mydataid[]');" /></th> <th>title</th> <th>details</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" name="mydataid[]" value="1" /></td> <td>stackoverflow</td> <td>some text here....</td> </tr> <tr> <td><input type="checkbox" name="mydataid[]" value="2" /></td> <td>google</td> <td> <a href="aaa.html">this link</a><br /> text here....<br /> <img src="something.jpg" /> </td> </tr> <tr> <td><input type="checkbox" name="mydataid[]" value="3" /></td> <td>test</td> <td>some text here....</td> </tr> </tbody> </table>
$('#anywhere_click tbody tr').click(function (e) { if(!$(e.target).is('#anywhere_click td input:checkbox')) $(this).find('input:checkbox').trigger('click'); }); $('#anywhere_click tr a').click(function (e) { e.stoppropagation(); });
Comments
Post a Comment