I have the following code:
$('a.confirm').click(function(e) {
e.preventDefault();
var answer = confirm("Are you sure?")
if (answer){
// do the default action
}
});
What code would I have to put in for the default action to be executed if the user confirms?
$('a.confirm').click(function(e) {
var answer = confirm("Are you sure?")
if (answer){
// do the default action
} else {
e.preventDefault();
}
});
or
$('a.confirm').click(function(e) {
var answer = confirm("Are you sure?")
if (!answer){
e.preventDefault();
}
});
or even just
$('a.confirm').click(function(e) {
return confirm("Are you sure?");
});
You can just return confirm("Are you sure?"). That will return true or false, where false prevents the action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With