Reputation: 7427
In my fiddle here:http://jsfiddle.net/qJdaA/2/
this code is suppose to disable the #monitor
button when there is none checked checkbox.
var checked = $('#status_table tr [id^="monitor_"]:checked');
if (checked.index()==-1){
$('#monitor').attr('disabled','true');
}
But it does not seem to be working. What's wrong?
EDIT: i found out i'm getting blurred with my code. to simplify the whole thing, may be i should change the logic :s How should i do it if i want to enable the monitor button ONLY if there is at least a checkbox been checked?
Upvotes: 0
Views: 91
Reputation: 50933
Try using this condition:
if (checked.length === 0) {
And you should use .prop()
, not .attr()
for setting the disabled state (as well as things like checked
and selected
).
So it would be:
$("#monitor").prop("disabled", true); // (or false, to enable it)
References:
.prop()
vs. .attr()
: .prop() vs .attr().prop()
: http://api.jquery.com/prop/Upvotes: 3