How to set ‚Äúchecked‚ÄĚ for a checkbox with jQuery?

Use the checked attribute to set the checkbox with jQuery. Also, the prop() method is used to get the property value.


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

Live Demo

<!DOCTYPE html>
  <title>jQuery Example</title>
  b {
     color: green;
  <script src=""></script>
<input id="checkbox1" type="checkbox" checked="checked">
<label for="checkbox1">Check/ Uncheck this checkbox</label>
$( "input" ).change(function() {
  var $input = $( this );
  $( "p" ).html(
    ".attr( \"checked\" ): <b>" + $input.attr( "checked" ) + "</b><br>" +
    ".prop( \"checked\" ): <b>" + $input.prop( "checked" ) + "</b><br>" +
    ".is( \":checked\" ): <b>" + $ ":checked" ) + "</b>" );