Get checkbox list values with jQuery Get checkbox list values with jQuery jquery jquery

Get checkbox list values with jQuery


$(document).ready(function() {    $('#someButton').click(function() {        var names = [];        $('#MyDiv input:checked').each(function() {            names.push(this.name);        });        // now names contains all of the names of checked checkboxes        // do something with it    });});


Since nobody has mentioned this..

If all you want is an array of values, an easier alternative would be to use the .map() method. Just remember to call .get() to convert the jQuery object to an array:

Example Here

var names = $('.parent input:checked').map(function () {    return this.name;}).get();console.log(names);