How to check or uncheck radio button dynamically using jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the jQuery prop() method

You can use the jQuery prop() method to check or uncheck radio button dynamically such as on click of button or an hyperlink etc. The prop() method require jQuery 1.6 and above.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <title>jQuery Check/Uncheck Radio Button</title>
  • <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
  • <script type="text/javascript">
  • $(document).ready(function(){
  •     $(".check-male").click(function(){
  •         $("#male").prop("checked", true);
  •     });
  •     $(".check-female").click(function(){
  •         $("#female").prop("checked", true);
  •     });
  • });
  • </script>
  • </head>
  • <body>
  •     <label><input type="radio" name="gender" id="male"> Male</label>
  •     <label><input type="radio" name="gender" id="female"> Female</label>
  •     <button type="button" class="check-male">I'm Male</button>
  •     <button type="button" class="check-female">I'm Female</button>  
  • </body>
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.