Download and Install
npm install sweetalert
//use CDN: you can also find SweetAlert on unpkg and jsDelivr and use the global swal variable.
//a sweet alert with only title and content
swal("A title", "Content goes here");
title: "Popup title",
text: "Congratulations! The article was updated successfully.",
placeholder: "Your Age",
- title: the title of the modal
- text: the main content of modal
- icon: there are 4 built-in icons that you can use – success, info, warning, and error.
- button: this is the default confirm button. If you want to replace both cancel and confirm buttons, you need to use buttons parameter.
- className: apply a custom class name to the modal.
- closeOnClickOutside: determine whether the modal is closed if user click outside of the modal.
- closeOnEsc: determine whether the modal is closed when user presses Escape.
- dangerMode: this is useful to show warning message. If this value is set to true, confirm button’s background is turned into red.
- timer: the modal is closed after x miliseconds.