Programmatically checking and unchecking a checkbox using jQuery

 
The following statements check the checkbox and uncheck the checkbox respectively.
 
$('#isContractWorker').prop('checked', true); // Checks the checkbox
$('#isContractWorker').prop('checked', false); // Unchecks the checkbox
 
In the above statements the # stands for id. 
 
An id may generally appear only once in a page, while on the other hand a class 
(represented by a . prefix), may appear more than once. 
 
When a class appears more than once, it is necessary to qualify the exact class, 
which needs to be affected, by the command.
 
In the example below, you will find out that the checkbox represented by 
class "isContractWorker" which is part of the id "viewModal" is specifically
addressed.
 
$('#viewModal .isContractWorker').prop('checked', true); 
 
Hope this solved your problem! 
 
Please note that this example works on jQuery versions above 1.6.

No comments:

Bluetooth on off Switch missing in Windows 10

  Sometimes, what happens is that you are unable to switch the Bluetooth in your PC or laptop. Even if you are a professional, it gets you f...

Most Popular

Copyrighted.com Registered & Protected DWYE-NHTO-NBNH-7FFM