If you have a checkbox in a form you can use jQuery to read and set the data in the checkbox. Here is the HTML we’ll use an example for our checkbox:
Reading a Checkbox
When using jQuery and you wish to read whether a checkbox is checked or not.
This will return
true if the checkbox is checked and
false if left unchecked.
Checking or Unchecking the Checkbox
Use the .prop() function to manipulate the checkbox.
The attr() function of jQuery has been deprecated since 1.6. However if you’re jQuery version is below 1.6 you must use this method.