- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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>
- Related Articles
- How to disable/enable an input box with jQuery?
- How to enable and disable submit button using jQuery?
- How to set “checked” for a checkbox with jQuery?
- How to Disable / Enable a Button in TKinter?
- How to enable/disable data connection in iOS programmatically?
- How to enable/disable the GPS programmatically in Android?
- jQuery :checkbox Selector
- How to enable or disable the GPS programmatically on Kotlin?
- How to disable right click using jQuery?
- Enable and disable interrupts in Arduino
- How to enable or disable interlace using imageinterlace() function in PHP?
- How can I disable/enable GPS programmatically in android?
- How to disable copy content function using jQuery?
- How to globally disable an animation using jQuery?
- How to enable or disable local user on Windows OS using PowerShell?

Advertisements