//Function called by sigle element or multiple times (see below)
$('[id^=old_]').change(function(){
var check = $(this).prop('checked') ? true : false;
if(check){
/* stuff here */
}else{
var reprise = confirm('Are you sure?');
if(reprise){
/* do stuff */
}else{
$(this).prop('checked', true);
}
}
});
//Function called on "select all/deselect all"
$('#span_descr > div:last-child').on('click', 'span:first-child', function(){
$('[id^=old_]:not(:checked)').click();
}).on('click', 'span:last-child', function(){
$('[id^=old_]:checked').click();
});
My problem is that on "deselect all" click I get an alert/confirm message for each deselected items. Is there a way to avoid that and get only once this message?
Check out jQuery one().
jquery
jSFiddle