How to check or uncheck a checkbox with jQuery

If you are using jQuery 1.5 and below you need to use .attr(). Here it is

1
2
3
4
5
6
7
8
9
 
To check <input class="checkbox" /> use 

$('.checkbox').attr('checked','checked');

To uncheck <input class="checkbox" /> use 

$('.checkbox').removeAttr('checked');

But if you are using jQuery 1.6+ use this code:

1
2
3
4
5
6
7
8
9
 
To check <input class="checkbox" /> use 

$('.checkbox').prop('checked', true);

To uncheck <input class="checkbox" /> use 

$('.checkbox').prop('checked', false);
Share:

Related Articles:

This entry was posted in Resources and tagged , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>