
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Disable/Enable Checkbox with jQuery
fTo disable and enable checkbox, use the attr() method.
Initially set the input type checkbox and disable it −
<input type="checkbox" id="sName" name= "Male" style="width: 25px" value="male" disabled="disabled"/>Male
Now on the click of a button, toggle between disabled and enabled checkbox −
$("#button1").click(function() { $("#sName").attr('disabled', !$("#sName").attr('disabled')); });
Example
<html> <head> <title>jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function() { $("#sName").attr('disabled', !$("#sName").attr('disabled')); }); }); </script> </head> <body> <input type="checkbox" id="sName" name= "Male" style="width: 25px" value="male" disabled="disabled"/>Male <br> <br> <input type="button" id="button1" value="Disable/ Enable" /> </body> </html>
Advertisements