Programming Tips - jQuery: Get the value of a checkbox

Date: 2016feb3 Update: 2025sep15 Library: jQuery Language: javaScript Keywords: checked, ischecked, check Q. jQuery: Get the value of a checkbox A. Assuming you have:
<input type=checkbox id=mycheck> My Check
Get the value as a boolean with prop('checked')
const mycheck = $('#mycheck').prop('checked');
That gets you boolean, if you prefer "yes" or "no"
const mycheck = toYesNo($('#mycheck').prop('checked'));
Using this function:
function toYesNo(b) { return b ? 'yes' : 'no'; }
Do NOT use .attr()
const mycheck = $('#mycheck').attr('checked'); // WRONG
Do NOT use val()
const mycheck = $('#mycheck').val(); // WRONG // Gives you value= from the html no matter if checked or not