javascript - $('input[type=checkbox]:checked').each not executing second time around -
i have following code on second execution not executed though check boxes checked. please help.
edit: added code gets rows in table have been checked using checkboxes. sorry there code post. second time around correct rows second function itterates checked checked boxes not run.
$('input[type=checkbox]').each(function() { if (this.checked == true){ var del_id = $(this).parents("tr").data(); console.log('!del_id', del_id); del_arr.push(del_id.id); mydata ={"spreadsheets_ids": del_arr}; console.log('mydata:', mydata); } }); ///off ajax call , lots of other stuff happens
before comes below
$('input[type=checkbox]:checked').each(function() { var $tr = $(this).closest('tr'); var del_id = $tr.attr('data-id'); console.log('still deleted: =' + del_arr); $.each(del_arr, function(index, value ) { console.log('even still deleted: =' + del_arr); if (value == del_id){ $tr.remove(); console.log('removing :'+ del_id +' , ' + value); return false; } }); }) $('input[type=checkbox]').each(function() { $(this).prop('checked', false); if (this.checked == true){ console.log('i still checked') } });
you haven't wrapped each
in change
event handler of checkbox
.
$(':checkbox').on('change', function() { $(':checkbox:checked').each(function() { var $tr = $(this).closest('tr'); var del_id = $tr.attr('data-id'); $.each(del_arr, function(index, value) { if (value == del_id) { $tr.remove(); return false; } }); }); });
Comments
Post a Comment