Reputation: 849
I have the following HTML (many, many rows):
<tr>
<td class="order_row"><input type="checkbox" name="data[Order][id][]" value="951"></td>
<td class="order_row">04/03/2014</td>
<td class="order_row">Test</td>
<td class="order_row">123</td>
</tr>
Anytime I click on any TD, I want to check the checkbox in that row. I have something like this:
$('.order_row').css('cursor', 'pointer').click(function() {
$(this).parent('tr').find('input').trigger('click');
});
But that's not working. Any help?
Upvotes: 0
Views: 2887
Reputation: 2880
$(function(){
$('.order_row').css('cursor', 'pointer').click(function() {
var checkbox = $(this).parent('tr').find('input[type=checkbox]');
if(checkbox.length > 0 && checkbox.is(':checked')) alert('checked!');
});
});
Upvotes: 0
Reputation: 1566
If you want toggle on of checked by clicking on td you can use this code
<script type="text/javascript">
$(document).ready(function(){
$('.order_row').css('cursor', 'pointer').click(function() {
var checkBoxes = $(this).parent('tr').find('input:checkbox')
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
})
</script>
Upvotes: 1
Reputation: 62488
Here is the code for it:
$(document).ready(function(){
$('table').on('click','.order_row',function() {
$(this).parent('tr').find('input').prop("checked",true);
});
});
Upvotes: 0