Detach is working fine but not append. I thought the array was building right but when appending again, array is undefined. Also, I will need to keep from adding the same element to the array if unchecked multiple times.
JSFiddle: http://ift.tt/2AUV4Ic
$(document).ready(function(){
var restoreMe = [];
$("#studentCourses :checkbox").change(function() {
var courseid = $(this).attr('id'),
row = $(this).closest('tr'),
cell = row.children('td').eq(3),
course = cell.find('input');
if($(this).prop("checked")) {
//var rm = $.grep(restoreMe, function(e){ return e.courseid.to_string == courseid.to_string; });
row.css('color', '#000000');
restoreMe[courseid].appendTo( cell );
//rm[0].courseid.appendTo( cell );
} else {
row.css('color', '#c0c0c0');
restoreMe.push({courseid: course.detach()});
}
});
});
Aucun commentaire:
Enregistrer un commentaire