0

I am dynamically checking chekboxes by using below function.

$('input[type="checkbox"]').each(function() {
    $(this).attr('checked', true);   
});

I want to store whole checked checkboxes in string.

Regent
  • 5,142
  • 3
  • 21
  • 35
Alekhya Vemavarapu
  • 1,145
  • 1
  • 10
  • 26

1 Answers1

1
var ids =''
$('input[type="checkbox"]').each(function() {
    if($(this).attr('checked')=='checked'){
        ids += $(this).attr(id) + ',';
    } 
});

You may also then split ids by comma and acquire an array of IDs

var ids = ids.split(',')
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • 2
    `var ids = $('input:checkbox:checked').map(function() { return this.id; }).get();` is much shorter – Regent May 14 '15 at 10:32