sweet alert modal code example

Example 1: sweet alert 2 do action on confirm

Swal.fire({  
  title: 'Do you want to save the changes?',  
  showDenyButton: true,  showCancelButton: true,  
  confirmButtonText: `Save`,  
  denyButtonText: `Don't save`,
}).then((result) => {  
	/* Read more about isConfirmed, isDenied below */  
    if (result.isConfirmed) {    
    	Swal.fire('Saved!', '', 'success')  
    } else if (result.isDenied) {    
    	Swal.fire('Changes are not saved', '', 'info')  
 	}
});

Example 2: switch alert

swal({
	title: "Good job!",
	text: "You clicked the button!",
	icon: "success",
	button: "Aww yiss!"
});

Example 3: sweet alert

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

Example 4: change icon in sweet alert

swal({  icon: "error",});

Example 5: sweetalert2 example html

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

Tags:

Css Example