DiegoP.
DiegoP.

Reputation: 45737

Know if one or more checkboxes are checked in Jquery

Is there a way in jQuery to know if at least one checkbox has been checked?

I have a form with a lot of checkboxes and each one is different.

I need a way with jQuery to say something like this, this is the logic:

If at least one of the checkboxes in this specific form has been checked, then DO THIS else DO THAT.

I repeat each checkbox has a different name, id and value. So I need something generic.

Instead the form is only one and the ID is #tuitting_form

Thanks!!

Upvotes: 2

Views: 614

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this

$(document).read(function(){

 $("#tuitting_form input:checkbox").live('click', function(){

    if( $("#tuitting_form input:checkbox:checked").length > 0){
       $("#send_message").show(); $("#remove_accounts").show(); 
    }

 });
});

Upvotes: 5

Wulf
Wulf

Reputation: 3898

if ($('#form input:checked').length > 0)  //...

Upvotes: 1

Related Questions