How to set “checked” for a checkbox with jQuery?

Use the checked attribute to set the checkbox with jQuery. The prop() method is the recommended approach for getting and setting properties like checked, while attr() handles HTML attributes.

Setting Checkbox to Checked

To programmatically check a checkbox, use the prop() method with the value true ?

// Check a checkbox
$("#myCheckbox").prop("checked", true);

// Uncheck a checkbox  
$("#myCheckbox").prop("checked", false);

Complete Example

You can try to run the following code to learn how to set checked for a checkbox ?




  jQuery Checkbox Example
  
  






Key Differences

Understanding the difference between these methods is important ?

  • prop("checked") ? Returns the current state (true/false)
  • attr("checked") ? Returns the HTML attribute value
  • is(":checked") ? Returns boolean for current checked state

Conclusion

Use prop("checked", true) to check a checkbox and prop("checked", false) to uncheck it. The prop() method is preferred over attr() for boolean properties in modern jQuery.

Updated on: 2026-03-13T18:13:10+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements