jQuery check if checkbox is checked (and JavaScript checked property)

Tech reviewed: Deepak Prasad
jQuery check if checkbox is checked (and JavaScript checked property)

jQuery check if checkbox is checked and javascript check if checkbox is checked both read the same DOM value: the live boolean HTMLInputElement.checked. In jQuery use .prop('checked') or .is(':checked')—not .attr('checked'), which reflects initial markup, not the current UI state (MDN: checked, jQuery .prop()). For structuring UI code, see JavaScript classes.

Tested on: all examples in this tutorial were run with Node.js v20.18.2 running the same logic under jsdom 24 with jQuery 3.7.1 (browser DOM + jQuery APIs), and the output shown below each snippet is its exact console output.


Quick reference

Use this table when you need the smallest answer for check if checkbox is checked jquery vs js check if checkbox is checked: live property vs default attribute, and jQuery selector helpers.

Need Use
Live boolean in plain JS element.checked
Live boolean with jQuery $(el).prop('checked')
Boolean test in a jQuery set $(el).is(':checked')
Initial default from markup element.defaultChecked or the HTML checked attribute

Setup (jsdom + jQuery)

Minimal HTML used for the logs below. For jquery checkbox checked examples, load jQuery (for example 3.7.1) so window.jQuery and $ exist in your script or console.

html
<input type="checkbox" id="age_checked" />
<input type="number" id="age_textbox" hidden />
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

Vanilla checked — js check if checkbox is checked

The native property is the direct js check if checkbox is checked path: read cb.checked for a boolean, assign true or false to toggle without touching attributes.

javascript
const cb = document.getElementById("age_checked");
console.log("default checked:", cb.checked);
cb.checked = true;
console.log("after assignment checked:", cb.checked);
cb.checked = false;
console.log("after uncheck checked:", cb.checked);
text
default checked: false
after assignment checked: true
after uncheck checked: false

jQuery is checked — .prop('checked') and .is(':checked')

Both patterns answer jquery is checked and check if checkbox is checked jquery: .is(':checked') fits filter-style truth tests; .prop('checked') returns an explicit boolean and is often clearer when you also set state.

javascript
const cb = document.getElementById("age_checked");
const $ = window.jQuery;
cb.checked = false;
console.log("is :checked (unchecked):", $("#age_checked").is(":checked"));
console.log("prop checked (unchecked):", $("#age_checked").prop("checked"));
cb.checked = true;
console.log("is :checked (checked):", $("#age_checked").is(":checked"));
console.log("prop checked (checked):", $("#age_checked").prop("checked"));
text
is :checked (unchecked): false
prop checked (unchecked): false
is :checked (checked): true
prop checked (checked): true

Use either form for jquery check if checkbox is checked; .prop('checked') is often clearer when you assign checked state as well as read it.


.attr('checked') vs .prop('checked') — jquery checkbox checked pitfall

This snippet shows why jquery checkbox checked tutorials warn against .attr('checked') for live state: with no checked attribute in the HTML, .attr stays undefined while .prop reflects the real toggle.

javascript
const cb = document.getElementById("age_checked");
const $ = window.jQuery;
cb.checked = true;
console.log($("#age_checked").attr("checked"));
console.log($("#age_checked").prop("checked"));
text
undefined
true

change handler — if checkbox is checked jquery pattern

Prefer the change event over click for if checkbox checked javascript and if checkbox is checked jquery flows so keyboard toggles and assistive tech stay aligned. The vanilla example dispatches change after programmatic updates; jQuery listeners should use a classic function callback (not an arrow) if you read this.checked.

javascript
const ageCheckbox = document.getElementById("age_checked");
const ageInput = document.getElementById("age_textbox");
ageCheckbox.checked = false;
ageInput.hidden = true;
ageCheckbox.addEventListener("change", function () {
  ageInput.hidden = !this.checked;
});
ageCheckbox.dispatchEvent(new window.Event("change", { bubbles: true }));
console.log("hidden after change (unchecked):", ageInput.hidden);
ageCheckbox.checked = true;
ageCheckbox.dispatchEvent(new window.Event("change", { bubbles: true }));
console.log("hidden after change (checked):", ageInput.hidden);
text
hidden after change (unchecked): true
hidden after change (checked): false

Equivalent jquery if checkbox is checked style (use function, not an arrow, so this is the DOM element):

javascript
$("#age_checked").on("change", function () {
  $("#age_textbox").prop("hidden", !this.checked);
});

Summary

  • Read live state with element.checked or $(el).prop('checked') for javascript check if checkbox is checked and jquery check if checkbox is checked.
  • Use $(el).is(':checked') when a truthy filter-style test fits your jquery is checked code.
  • Avoid .attr('checked') for current UI; use .prop or the property for jquery checkbox checked behavior.
  • Listen on change for if checkbox is checked jquery UI patterns; dispatch change/input if programmatic checked updates must run handlers.
  • Compare defaultChecked when you care about the original HTML default, not the live value.

References

MDN and jQuery docs for checked, events, .prop(), and the :checked selector—sources behind this check if checkbox is checked jquery guide.


Frequently Asked Questions

1. jquery check if checkbox is checked in one line?

Use $('#id').prop('checked') for a boolean, or $('#id').is(':checked'). Both read the live DOM property, not the initial HTML attribute.

2. jquery is checked vs .attr('checked')?

Use .prop('checked'). The checked HTML attribute reflects default state; .attr('checked') does not update when the user toggles the box. MDN documents checked vs defaultChecked on HTMLInputElement.

3. javascript check if checkbox is checked without jQuery?

Use document.querySelector('#id').checked or inputElement.checked. It is a boolean on HTMLInputElement for type checkbox or radio.

4. Should I use click or change for checkbox is checked jquery?

Prefer the change event so keyboard and programmatic updates stay consistent. click still fires for mouse users, but change matches accessibility and form semantics.

5. Why does my jQuery arrow function see the wrong this?

Arrow functions do not bind their own this. For $('#cb').on('change', function () { this.checked }) use a classic function, or read the target from the event object.

6. If I set checkbox.checked = true in code, will my change handler run?

Not automatically in most browsers. Dispatch an input or change event if other code must react to the programmatic update.
Steve Alila

Specializes in web design, WordPress development, and data analysis, with proficiency in Python, JavaScript, and data extraction tools. Additionally, he excels in web API development, AI integration, and data presentation using Matplotlib …

  • Machine Learning with Python
  • Data Analysis with Python
  • JavaScript Algorithms and Data Structures
  • Git
  • JavaScript
  • Laravel
  • Python (programming language)