How to check or uncheck checkbox using jQuery?


I have some filters on page so when clicking on "x" button of a selected filter, need to remove the filter and uncheck the checkbox using jQuery, so How can I do that on dynamically created element using jQuery?


Asked by:- Vinnu
0
: 598 At:- 4/6/2019 8:01:37 AM
jQuery HTML check-uncheck-checkbox






1 Answers
profileImage Answered by:- manish

jQuery prop() method can be used to check or uncheck a checkbox dynamically

The prop() method require jQuery 1.6 and above, here is the sample

$('#YouCheckboxId').prop('checked', true); // Check
$('#YouCheckboxId').prop('checked', false); // Uncheck, may not work in some browsers

$('#YouCheckboxId').removeAttr('checked'); //uncheck, by removing attribute

Below jQuery 1.6 you can use .attr()

$('#YouCheckboxId').attr('checked', true); // Check 
$('#YouCheckboxId').attr('checked', false); // Uncheck

Note: An element is considered checked as long as it has the attribute of checked even if it has no value or the value is like 'false' or whatever, so to uncheck the checkbox, it is safe to use attribute removeAttr("checked").

0
At:- 4/9/2019 10:56:05 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly