Mark Richards
Mark Richards

Reputation: 434

do not want to check a check box which is disabled

i have check box list and some of them are disable. i have a check box of check_all and uncheckall and my code is

$( '#check_all' ).live( 'change', function() {
   $( '.waiting_user' ).attr( 'checked', $( this ).is( ':checked' ) ? 'checked' : '' );
   $( this ).next().text( $( this ).is( ':checked' ) ? 'Uncheck All' : 'Check All' );
 }); 

its working fine but problem is that it check and uncheck disabled checkbox also

any way to do that checkall and unchekall only enabled echeck box se in image to more detailenter image description here

and problem is its cheked disabled checkbox also.

enter image description here

Upvotes: 0

Views: 43

Answers (3)

monxas
monxas

Reputation: 2657

$( '#check_all' ).live( 'change', function() {
$( '.waiting_user:enabled").attr( 'checked', $( this ).is( ':checked' )  ? 'checked' : '' );
$( this ).next().text( $( this ).is( ':checked' ) ? 'Uncheck All' : 'Check All' );
});

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

You can use the psuedo class selector :enabled

 $( '.waiting_user:enabled' ).attr( 'checked', $( this ).is( ':checked' ) ? 'checked' : '' );

Upvotes: 2

David Hedlund
David Hedlund

Reputation: 129832

You can exclude the disabled checkboxes as such:

$('.waiting_user:not(:disabled)')

Upvotes: 2

Related Questions