SyntaxStudy
Sign Up
jQuery SweetAlert2 for Dialogs
jQuery Beginner 3 min read

SweetAlert2 for Dialogs

SweetAlert2

SweetAlert2 replaces ugly browser alert(), confirm(), and prompt() dialogs with beautiful, customizable modals.

Example
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
// Simple alert
Swal.fire("Saved!", "Your changes have been saved.", "success");

// Confirm dialog
Swal.fire({
  title: "Delete this record?",
  icon: "warning",
  showCancelButton: true,
  confirmButtonText: "Yes, delete it"
}).then(result => {
  if (result.isConfirmed) {
    $.delete("/api/items/" + id);
  }
});
</script>
Pro Tip

SweetAlert2 works with async/await for clean confirm-then-action patterns.