Categories
jQuery

How to check checkbox with jQuery?

The correct way to check checkbox on the DOM elements can be done using jQuery .prop or .attr method.

By using JavaScript’s “checked” property, we can solve the problem directly, instead of manipulating the DOM into doing what we want it to do.

You may like:  Enable or disable an input field with jQuery

To check checkbox see the below script:

After jQuery version 1.6 you can use:

$('.chkID').prop('checked', true);
$('.chkID').prop('checked', false);

And jQuery version 1.5x and below you can use:

$('.chkID').attr('checked', true);
$('.chkID').attr('checked', false);

Read: jQuery Checkbox checked property

This plugin will alter the checked property of any DOM elements selected by jQuery, and successfully check or uncheck checkboxes under all circumstances.

Avatar for Namaste UI

By Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Leave a Reply

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