jQuery see if any or no checkboxes are selected

前端 未结 8 1705
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 13:41

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 check

8条回答
  •  我在风中等你
    2020-12-02 14:36

    You can do this:

      if ($('#form_id :checkbox:checked').length > 0){
        // one or more checkboxes are checked
      }
      else{
       // no checkboxes are checked
      }
    

    Where:

    • :checkbox filter selector selects all checkbox.
    • :checked will select checked checkboxes
    • length will give the number of checked ones there

提交回复
热议问题