How to change a Checkbox attribute on click of parent <tr>
I need small suggestion from you.
Onclick of the checkbox attribute inside that should be changed.There is also a inside the
HTML Code:
<table>
<tr>
<td class="answer"><input tabindex="4" type="checkbox" name="Dum1_4" id="Dum1_4" value="1"/></td>
<td class="answerlabel"><label for="Dum1_4" id="Dum1_4_label"><table class="sample"><tr><td><img src="/ThumbsV2/2200000999-f.png"></td></tr><tr><td&开发者_StackOverflow社区gt;<b>Product 4</b></td></tr><tr><td>Product Description 4</td></tr><tr><td><b>Price 4</b></td></tr></table></label></td>
</tr>
<tr>
<td class="answer"><input tabindex="5" type="checkbox" name="Dum1_5" id="Dum1_5" value="1"/></td>
<td class="answerlabel"><label for="Dum1_5" id="Dum1_5_label"><table class="sample"><tr><td><img src="/ThumbsV2/2200001080-f.png"></td></tr><tr><td><b>Product 5</b></td></tr><tr><td>Product Description 5</td></tr><tr><td><b>Price 5</b></td></tr></table></label></td>
</tr>
</table>
Here is my code:
$('.sample').click(function()
{
row =$this.parents("td");
row.siblings().find("input:checkbox").attr("checked","checked" );
}
});
});
Please someone help me!
$('TABLE > TBODY > TR').click(function()
{
$('input:checkbox', $(this)).prop("checked", "checked");
});
try
$('TABLE TBODY TR').click(function()
{
$(this).find('input:checkbox').attr("checked", "checked");
});
There's a decent SO thread about manipulating checkboxes with jQuery
View example here
If you are trying to toggle the selected state, use the following:
jQuery 1.6+
$('table tbody tr').click(function() {
$('input:checkbox', this).prop('checked', function(index, oldValue) {
return !oldValue;
});
});
jQuery pre-1.6
$('table tbody tr').toggle(function() {
$('input:checkbox', this).attr('checked', 'checked');
}, function() {
$('input:checkbox', this).removeAttr('checked');
});
Changing the value of the attribute to "checked"
should work.
$('TABLE TBODY TR').click(function()
{
$(this).find('input:checkbox').attr("checked", "checked");
});
See it in action.
try this
$(this).find('input:checkbox').attr("checked","checked");
With jQuery 1.6, the code is more readable:
$("table tbody tr").click(function(){
$(this).find("input[type='checkbox']").prop("checked",true);
});
this was working fine for me:
$('#checkall').click(function() {
$('#cause').children().each(function() {
$(this).find("input[type='checkbox']").prop("checked", $('#checkall').prop("checked"));
});
});
just use it without the each function / check / uncheck all elements
精彩评论