jQuery see if any or no checkboxes are selected Ask Question

jQuery see if any or no checkboxes are selected Ask Question

I know how to see if an individual checkbox is selected or not.

But Im having trouble with the following - given a form id I need to see if any of the checkboxes are selected (i.e 1 or more), and I need to see if none are selected. Basically I need two separate functions that answer these two questions. Help would be appreciated. Thanks!

Actually, I would just need a function to tell me if none are selected. Knowing this would answer the other question.

ベストアンサー1

You can use something like this

if ($("#formID input:checkbox:checked").length > 0)
{
    // any one is checked
}
else
{
   // none is checked
}

おすすめ記事