Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery click event

Tags:

jquery

I have a delete button on my web site which I want to add a confirm box to. I have wrote the following code in JQuery but I'm unsure how to continue with the page load if the user confirms the delete. e.g. what do I put inside the if statement to reverse the preventDefault?

$(".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

            }
        });

Thanks

like image 709
John Avatar asked Jan 20 '26 17:01

John


1 Answers

e.preventDefault() has the same function as simple 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?');
});

Don't know what you're trying to do but this should answer your question.

Note that this function cannot stop the page from loading, as when this function is called, the page has already loaded. So give an example of what you're trying to do if you need a more specific answer.

like image 128
Tatu Ulmanen Avatar answered Jan 23 '26 20:01

Tatu Ulmanen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!