yvonnezoe
yvonnezoe

Reputation: 7427

button attribute "disable" not working

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

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388436

Try

$('#monitor').prop('disabled',true);

Demo: Fiddle

Upvotes: 1

Ian
Ian

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:

Upvotes: 3

Related Questions