My issue is relating to dynamically applied elements to a page that I am running a confirm against. The code correctly targets the element and asks the confirmation part, however the problem is if I select Yes, I have no idea where the return value is hidden, it is not set in the class like my thoughts below, nor does it return a value of sorts.
Anyone know how I can get some form of return value from the confirm for the element that I wish to delete?
$('.deleteMe').live('click', function() {
confirmFunction(this);
if ($(this).hasClass('confirm')){ alert("yea");} else {alert("no");}
});
function confirmFunction(element) {
$(element).confirm({
msg:'Confirm Action!<br />',
stopAfter:'ok',
eventType:'click',
timeout:5000,
buttons: { ok:'Yes', cancel:'No', separator:' - '}
});
}
From my understanding of the examples on the plug-in page, it should be like this:
Assign the click handler that should run if confirmation is successful, then assign the confirm plugin.
Due to the dynamic nature you mentioned, you would need to call updateConfirms() after adding new elements that need confirmations.
EDIT: Let’s try not using Live, and refreshing the click handler and the confirm after any additions: