I have some divs. Each of them contains two checkbox (each checkbox is in a div of a same class 'class3'). I would that when the user checks the first checkbox, the second one is checked and disabled. I've tried with :
$('.class1').live('click', function () {
var n = $(this).siblings('input:checkbox');
if ($(this).attr('checked')) {
n.attr('disabled', true);
} else {
n.attr('disabled',false);
}
return false;
});
In this way the two checkbox are enabled, but when I click on the first one, the check doesn't appear and nothing happens.
<div class="elements">
<div class="class3">
<input class="class1" type="checkbox" value="1" name="first" id="first" />
</div>
<div class="class3">
<input class="class2" type="checkbox" value="1" name="second" id="second" />
</div>
</div>
.prop('disabled', true)is perfectly correct, as per the examples in the jQuery documentation.prop(), but it's (incorrectly) using.attr(), in which case it may very well be.attr('disabled', 'disabled'). Though, again, they should be using.prop()instead.