How do I check whether a checkbox is checked in jQuery?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In jQuery, the usual way to test a checkbox is is(':checked') or prop('checked'). Both inspect the current DOM state, which is what you want when the user may have changed the checkbox after page load.
The Two Standard Patterns
For a single checkbox, the most readable form is usually:
The equivalent property-based version is:
In everyday jQuery code, either approach is acceptable. is(':checked') reads more like a question, while prop('checked') feels more explicit about reading a DOM property.
Why attr('checked') Is The Wrong Tool
Older examples sometimes use attr('checked'), but that reads the HTML attribute rather than the live checkbox state.
If the user clicks the checkbox, the property changes immediately. The original HTML attribute may not reflect that interactive state.
That is why modern jQuery guidance is:
- use
:checked - or use
.prop('checked') - avoid
.attr('checked')for state checks
Check The State During Events
You often want to read the checkbox inside a change handler:
This is a common pattern for:
- enabling submit buttons
- turning feature panels on and off
- filtering UI state
- reacting to consent or preference toggles
The important detail is that you are reading the current state at the moment of the event.
Working With Multiple Checkboxes
If you need to know how many checkboxes are checked, use the selector directly:
If you need their values:
That is clearer than manually looping through every checkbox and inspecting each one separately.
Form Validation Example
Checking the box state during form submission is another common case:
This is a good example of why you should inspect the live state instead of assuming the original markup tells you what the user did.
If you are dealing with dynamically inserted checkboxes, the same checking logic still applies, but the event binding may need delegation:
That matters in older jQuery-heavy applications where rows or forms are added after the initial page render.
It also makes debugging easier because delegated handlers confirm that the checkbox exists at the time the event fires, not only at initial page load.
Common Pitfalls
One common mistake is using attr('checked') and then wondering why the result does not follow user clicks.
Another issue is calling .is(':checked') on a selector that matches nothing. In that case the result is false, which may hide the fact that the element was never found.
A third problem is checking the box state before the DOM is ready or before the element has been inserted dynamically.
Finally, in modern codebases that do not already use jQuery, adding jQuery solely for checkbox checks is unnecessary because plain DOM APIs handle this easily too.
Summary
- Use
$('#id').is(':checked')for a readable single-checkbox test. - Use
.prop('checked')when you want the live boolean property explicitly. - Avoid
.attr('checked')for interactive state. - Read the checkbox state inside
changeorsubmithandlers when behavior depends on user input. - For groups of checkboxes,
$('.class:checked')is the cleanest pattern.

