How to check or uncheck a checkbox with jQuery

Share

Check or uncheck a checkbox with jQuery is a simple task and can be achieved very easily. If you are using jQuery 1.5 and below you need to use .attr(). Here it is


To check  use 

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


To uncheck  use 

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

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


To check  use 

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


To uncheck  use 

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

That’s it 🙂

  • May 12, 2014
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure