jQuery: Test if checkbox is NOT checked

前端 未结 18 976
太阳男子
太阳男子 2020-12-02 07:12

I\'m having trouble figuring this out. I have two checkboxes (in the future will have more):

  • checkSurfaceEnvironment-1
  • checkSurface
18条回答
  •  失恋的感觉
    2020-12-02 08:11

    You can also use either jQuery .not() method or :not() selector:

    if ($('#checkSurfaceEnvironment').not(':checked').length) {
        // do stuff for not selected
    }
    

    JSFiddle Example


    Additional Notes

    From the jQuery API documentation for the :not() selector:

    The .not() method will end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter. In most cases, it is a better choice.

提交回复
热议问题