Alex Rivera | Logout

Determine if all checkboxes within jQuery object are checked, return as boolean

Asked 2010-09-15T16:46:44.267
10

Hey all. I've been been trying to figure this out for a while now.

I create a jQuery object of checkboxes and store it in a variable:

$group1 = $('#checkbox1,#checkbox2,#checkbox3,#checkbox4');

The user cannot continue unless all checkboxes in that group are checked.

I've been using an if statement combined with .is(':checked') to find a boolean value:

if( $group1.is(':checked') ){
  //continue is OK
}

...but .is(':checked') will return TRUE if any checkboxes are checked within the group. Essentially, .is(':checked') performs an OR operation on the selected elements in $group1. I'm looking for an AND operation, so all selected elements must be checked to return TRUE. Is there a jQuery function that does this, or another workaround?

Edit
Report

1 Answer

21

@Adam is off just a bit

if( $group1.filter(':not(:checked)').length === 0){
  //continue is OK
}
answered 2010-09-15T16:55:01.220

Your Answer