Easiest way to create a confirmation message with jQuery/JavaScript?

javascript, jquery

Solution

Javascript provides a builtin confirmation dialog.

if (confirm("Are you sure?"))
{
    // continue with delete
}

Problem

How can I achieve this? - A user clicks the delete link (with a class of "confirm"). - Confirmation message appears asking "Are you sure?" with "Yes" and "Cancel" options. If yes is selected, the link continues as clicked, but if cancel is selected, the action is canceled. Update: Final working code with `confirm()` thanks to this guy: ``` $('.confirm').click(function() { return confirm("Are you sure you want to delete this?"); }); ```

Original source