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:

Imagen 3: A New Era of AI Image Creation?

  Google has just unveiled Imagen 3, the latest iteration of their Gemini AI. They're making bold claims about enhanced image quality, ...

Most Popular

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