Get a list of checked checkboxes in a div using jQuery

Share Now

#HTML CODE

<div id="checkboxes">
    <input id="chkbx_0" type="checkbox" value="c_n_0" name="c_n_0" checked="checked" />Option 1
    <input id="chkbx_1" type="checkbox" value="c_n_1" name="c_n_1" checked="checked" />Option 2
    <input id="chkbx_2" type="checkbox" value="c_n_2" name="c_n_2" />Option 3
    <input id="chkbx_3" type="checkbox" value="c_n_3" name="c_n_3" checked="checked" />Option 4
</div>

#Here is the jQuery Needed

var selected = [];
$('#checkboxes input:checked').each(function() {
    selected.push($(this).attr('name'));
   //OR
   selected.push($(this).attr('value'));
});
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert