How to check a checkbox in jquery

To check a checkbox using jQuery, you can use the prop() method to set the checked property to true. Here’s an example:

HTML code:

<input type="checkbox" id="myCheckbox"> 

<label for="myCheckbox">Check me</label>

jQuery code:

$(document).ready(function() {
$('#myCheckbox').prop('checked', true);

In the code above, the prop() method is used to set the checked property of the checkbox with the ID myCheckbox to true. You can replace true with false to uncheck the checkbox.

Note that the above code assumes that you have included the jQuery library in your HTML file. If you haven’t done so, you can add the following script tag before the jQuery code:

<script src=""></script>

This will include the jQuery library from a CDN (Content Delivery Network).

Leave a Reply

Your email address will not be published. Required fields are marked *