Swall Alert code example

Example 1: sweet alert

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

Example 2: sweet alert js

swal({
     title: "Deleted!",
     text: "Your row has been deleted.",
     button: "Close", // Text on button
     icon: "success", //built in icons: success, warning, error, info
     timer: 3000, //timeOut for auto-close
      buttons: {
        confirm: {
          text: "OK",
          value: true,
          visible: true,
          className: "",
          closeModal: true
        },
        cancel: {
          text: "Cancel",
          value: false,
          visible: true,
          className: "",
          closeModal: true,
        }
      }
     });

Example 3: sweet alert add custom button

$(document).on('click', '.SwalBtn1', function() {
        //Some code 1
        console.log('Button 1');
        swal.clickConfirm();
    });
    $(document).on('click', '.SwalBtn2', function() {
        //Some code 2 
        console.log('Button 2');
        swal.clickConfirm();
    });

$('#ShowBtn').click(function(){
    swal({
        title: 'Title',
        html: "Some Text" +
            "<br>" +
            '<button type="button" role="button" tabindex="0" class="SwalBtn1 customSwalBtn">' + 'Button1' + '</button>' +
            '<button type="button" role="button" tabindex="0" class="SwalBtn2 customSwalBtn">' + 'Button2' + '</button>',
        showCancelButton: false,
        showConfirmButton: false
    });
 });

Example 4: change icon in sweet alert

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

Tags:

Html Example