How to check or uncheck checkbox input or radio button in jQuery

In this post , we will see how to check or uncheck checkbox or radio button in jQuery.
You can use prop() method to set "checked" as true or false. If you set it to true, it will be checked else it will be unchecked.
prop() function required jQuery 1.6 or more.
To check a checkbox/radio button.
$('selector').prop( "checked", true );
To uncheck a checkbox/radio button.
$('selector').prop( "checked", false);
Lets understand with the help of simple example:
<html>
<head>
<title>jQuery check/uncheck a check box example</title>
 <script src="http://code.jquery.com/jquery-2.2.3.min.js"></script>
</head>
<body>

<h1>jQuery check / uncheck a check box example</h1>

<script type="text/javascript">

  $(document).ready(function(){
 
    $("#checkIt").click(function () {

 $('#checkme').prop( "checked", true );

    });

    $("#UnCheckIt").click(function () {

 $('#checkme').prop( "checked", false );

    });

  });
</script>
</head><body>

<input id="checkme" type="checkbox" name="checkme">Check Me</input>

<br/>
<br/>
<input type='button' value='Check It' id='checkIt'>
<input type='button' value='UnCheck It' id='UnCheckIt'>

</body>
</html>

Live Demo: 

jQuery check/uncheck a check box example on jsbin.com

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus

 

Java tutorial for beginners Copyright © 2012