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:

A Guide to Understand Google Ads Quality Score

A Guide to Understand Google Ads Quality Score Introduction to Google Ads Quality Score Google assesses the quality and relevance of your...

Most Popular

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