Reputation: 22323
my html:
<div class="check">
<input class="sfCheckbox" type="checkbox" title="view" disabled="true" checked="checked">
<input class="sfCheckbox" type="checkbox" title="view" checked="checked">
</div>
in jquery i try:
$('.check .sfCheckbox').attr('checked', false);
code work fine but i want to ('checked', false)
if check box is not disable.How to get desire result.Thanks.
i mean if check box is disable do nothing .if not 'checked', false.Thanks.
Upvotes: 1
Views: 506
Reputation: 10705
Working code:
if($("input").attr("disabled")==undefined)
$('input').removeAttr('checked','checked');
Upvotes: 1
Reputation: 100205
Try:
if(!$(".check").is(":disabled")) {
$(this).attr('checked', false);
}
Upvotes: 1
Reputation: 2958
You can try this example. The explaination is that with $('.check') you are getting the div element and not the checkboxes. You havo to provide checkboxes selectors to achieve what you wanto
Upvotes: 1
Reputation: 66693
Try this:
Adding a .not('[disabled]')
in your statement will do the trick
$('.check .sfCheckbox').not('[disabled]').attr('checked', false);
This statement will uncheck all 'enabled'
check boxes with class sfCheckbox
that are inside an element with class check
Upvotes: 1
Reputation: 66398
If you're using jQuery 1.6 or higher, don't use .attr()
anymore, there is .prop()
instead:
$('selector goes here').prop('checked', false);
Upvotes: 2