jQuery see if any or no checkboxes are selected

前端 未结 8 1677
被撕碎了的回忆
被撕碎了的回忆 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:40

    This is the best way to solve this problem.

      if($("#checkbox").is(":checked")){
    
      // Do something here /////
    
      };
    
    0 讨论(0)
  • 2020-12-02 14:41

    Rahul's answer is best fit for your question. Anyway, if you have a group of checkboxes to be checked and not all the checkbox in your form, you can go for it.

    Put a classname for all the checkboxes you want to check, say for example, a classname test_check and now you can check if any of the checkbox is checked belonging to the group by:

    $("#formID .test_check:checked").length > 0
    

    If it returns true, assume that one or more checkboxes are checked having the classname test_check and none checked if returns false.

    Hope it helps someone. Thanks :)-

    0 讨论(0)
提交回复
热议问题