I've been through all of the posts here and none worked so far. I have list of checkboxes with the same class:
<input class="my_checkbox" type="checkbox" value="some_value1">
<input class="my_checkbox" type="checkbox" value="some_value2">
<input class="my_checkbox" type="checkbox" value="some_value3">
I can either toggle them individually or use a toggle button that checks/uncheck all:
$(document).on('click', '#toggle_button', function () {
if ($(this).prop("checked")) {
$(".my_checkbox").prop("checked", true);
} else {
$(".my_checkbox").prop("checked", false);
}
});
Now I want to get all the values into an array, and I've tried multiple things and none worked, the array always ends up empty.
I tried:
$('input:checkbox.my_checkbox').each(function () {
arr.push($(this).val());
});
and:
$('.my_checkbox:checkbox:checked').map(function() {
arr.push($(this).val());
}).get();
And some more, but nothing seem to work