How to check uncheck checkBox on Button click in jQuery?
<input type="checkbox" id="chkMango" value="Mango" /><label for="chkMango">Mango</label> <input id="btnCheckUncheck" type="button" value="Submit" />
Hi makenzi.exc,
On Button click, check if CheckBox is Checked then remove the checked attribute else add checked attribute.
Refer below example.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <input type="checkbox" id="chkMango" value="Mango" /><label for="chkMango">Mango</label> <input id="btnCheckUncheck" type="button" value="Submit" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#btnCheckUncheck").click(function () { if ($("#chkMango").is(":checked")) { $('#chkMango').removeAttr('checked'); } else { $('#chkMango').attr('checked', 'checked'); } }); }); </script> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.