Jquery click event

I have a delete button on my website to which I want to add a confirmation field. I wrote the following code in jQuery, but I'm not sure how to continue loading the page if the user confirms the deletion. for example, what do I put inside an if statement to cancel the preventDefault function?

$(".delete").click(function(e){
            e.preventDefault(); 

            if (confirm('Are you sure you want to delete this?')) {
                 NEED SOMETHING IN HERE TO CONTINUE WITH THE LOADING OF THE PAGE

            }
        });

thank

+3
source share
2 answers

e.preventDefault()has the same function as a simple one return false, so you can do this to achieve the same effect:

$(".delete").click(function(e){
    // Will continue if the user clicks 'Yes'
    return confirm('Are you sure you want to delete this?');
});

I don’t know what you are trying to do, but this should answer your question.

, , . , , .

+3

?

$(".delete").click(function(e){
    if (!confirm('Are you sure you want to delete this?')) {
        e.preventDefault();           
    }
});
+1

Source: https://habr.com/ru/post/1736276/


All Articles