$("#ans").attr('checked')
will tell you if it's checked. You can also use a second parameter true/false to check/uncheck the checkbox.
$("#ans").attr('checked', true);
Per comment, use prop
instead of attr
when available. E.g:
$("#ans").prop('checked')
manpreet
Best Answer
2 years ago
If the checkbox is checked, then I only need to get the value as 1; otherwise, I need to get it as 0. How do I do this using jQuery?
$("#ans").val()
will always give me one right in this case: