How can I get the value of checkboxes which are selected using jquery? My html code is as follows:
You can do it like this,
$('.ads_Checkbox:checked')
You can iterate through them with each() and fill the array with checkedbox values.
Live Demo
To get the values of selected checkboxes in array
var i = 0;
$('#save_value').click(function () {
var arr = [];
$('.ads_Checkbox:checked').each(function () {
arr[i++] = $(this).val();
});
});
Edit, using .map()
You can also use jQuery.map with get() to get the array of selected checkboxe values.
As a side note using this.value instead of $(this).val() would give better performance.
Live Demo
$('#save_value').click(function(){
var arr = $('.ads_Checkbox:checked').map(function(){
return this.value;
}).get();
});