How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Check if a Checkbox Is Checked with jQuery
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Check if a Checkbox Is Checked with jQuery
Web Development

How to Check if a Checkbox Is Checked with jQuery

how7o
By how7o
Last updated: May 22, 2026
4 Min Read
jQuery check if a checkbox is checked
SHARE

To check if a checkbox is checked with jQuery, the cleanest one-liner is $('#myCheckbox').prop('checked') — returns true or false based on the live DOM state. Alternative forms (.is(':checked'), :checked selector + .length) all work and have their place. Don’t use .attr('checked') — it reads the original HTML attribute, not the live state.

Contents
  • TL;DR
  • Pick the method that reads cleanly
  • Don’t use .attr('checked')
  • React to state changes
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with jQuery 3.7+. Originally published 2023-01-05, rewritten and updated 2026-05-17.

TL;DR

// Single checkbox — get the live boolean state
if ($('#agree').prop('checked')) {
  // ...
}

// Reads English-style
if ($('#agree').is(':checked')) {
  // ...
}

// "Are any of these checked?"
if ($('input[type="checkbox"]:checked').length) {
  // at least one is checked
}

// Vanilla JS
if (document.getElementById('agree').checked) {
  // ...
}

Pick the method that reads cleanly

All three jQuery forms work; choose based on what you’re expressing:

  • .prop('checked') — best for boolean math (assigning to a variable, passing to a function). Returns the literal boolean.
  • .is(':checked') — best inside an if for readability. Reads “if the element is checked…”
  • $('selector:checked').length — best for “is any of these checked?” without writing a loop.
jQuery check if checkbox is checked — .prop, .is(':checked'), :checked selector, vanilla JS

Don’t use .attr('checked')

// MISLEADING — returns the original HTML attribute, not the live state
$('#agree').attr('checked');     // "checked" or undefined, no matter what the user did

The HTML checked attribute reflects only the default state from the markup. After the user clicks, the live state lives on the DOM property — which is what .prop() reads. This trap has been the subject of “jQuery checkbox not working” Stack Overflow questions for over a decade.

React to state changes

$('#agree').on('change', function () {
  console.log('Checked:', this.checked);
});

this inside the handler is the raw DOM checkbox, so this.checked gives you the live boolean without wrapping in jQuery.

Frequently asked questions

Which method is the cleanest — :checked, .prop(), or .is()?

For a single checkbox: $('#agree').prop('checked') returns a boolean directly. For a selector that might match many checkboxes (“is any of these checked?”): $('input:checked').length > 0. For a one-off readability win inside a conditional: $('#agree').is(':checked') reads almost like English. All three are equivalent; pick the one that reads cleanest in context.

Why does $('#cb').attr('checked') sometimes give wrong results?

Because .attr('checked') reads the original HTML attribute (the default state from the markup), not the live state after the user clicks. .prop('checked') reads the live DOM property. For ‘is it checked right now?’ always use .prop() — this was the jQuery 1.6+ recommendation and still holds.

Can I do this without jQuery?

Yes: document.getElementById('agree').checked for a single element, or document.querySelectorAll('input:checked').length for a count. Native JS has been comfortable for this since forever — jQuery’s only advantage is the terse selector syntax.

How do I run code when the checkbox state changes?

Wire up the change event: $('#agree').on('change', function () { console.log(this.checked); });. The this inside the handler is the raw DOM element, so this.checked is the boolean state at the moment of the event.

Related guides

  • How to Add the Required Attribute to Input Fields with jQuery
  • How to Check if an Element Is Hidden in jQuery
  • How to Change a Checkbox Background Color with CSS

References

jQuery .prop(): api.jquery.com/prop. :checked selector: api.jquery.com/checked-selector.

TAGGED:JavaScriptjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Check Bootstrap modal open or closed with jQuery How to Check if a Bootstrap Modal Is Open or Closed with jQuery
Next Article Check if an element is hidden or visible with jQuery How to Check if an Element Is Hidden or Visible with jQuery
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Get the first character of a JavaScript string
Web Development

How to Get the First Character of a String in JavaScript

5 Min Read
PHP merge arrays without duplicates — union operator and array_unique
Web Development

How to Combine Two Arrays Without Duplicates in PHP

7 Min Read
WordPress admin notice — four notice types shown at the top of the admin area
Web Development

How to Show Custom Notifications in the WordPress Dashboard

6 Min Read
Laravel delete file from public folder — File::delete with public_path
Web Development

How to Delete Files from the Public Folder in Laravel

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?