Home > Software design >  How to change confirm button of Swal
How to change confirm button of Swal

Time:11-09

I'm using Sweetalertjs and I have coded this for showing a popup message to users:

$(document).ready(function(){
            let popup_shown = false;
            let cookies = document.cookie.split('; ');
            for( let i=0; i<cookies.length; i   ){
                cookie = cookies[i].split('=');
                if( cookie[0] == 'zxczxc' )
                    popup_shown = true;
            }
            if( !popup_shown ){
                    var popup_data = '{!! $output !!}'
                    Swal.fire({ html:popup_data });
                    document.cookie = "zxczxc=1; path=/";
            }
        });

And it works fine and perfect but I just need to know how to change the Cofirm button text which is by default set to Ok.

So I've searched and they said I can do this via this:

        swal({
            confirmButtonText: 'Yes, I am sure!',
        },

But this is wrong since I'm showing the popup by using Swal.fire.

So how can I change the confrim button text in this case?

CodePudding user response:

Swal.fire({
  title: '<strong>HTML <u>example</u></strong>',
  icon: 'info',
  html:
    'You can use <b>bold text</b>, '  
    '<a href="//sweetalert2.github.io">links</a> '  
    'and other HTML tags',
  showCloseButton: true,
  showCancelButton: true,
  focusConfirm: false,
  confirmButtonText:
    '<i ></i> Great!',
  confirmButtonAriaLabel: 'Thumbs up, great!',
  cancelButtonText:
    '<i ></i>',
  cancelButtonAriaLabel: 'Thumbs down'
})

please check it is explained on their official github page https://sweetalert2.github.io/

  • Related