Search code examples
javascriptjquerysweetalert

Sweet alert shows TRUE instead of alert text


I'm working with Sweet Alert to show some message so I coded this:

$(document).on('click', '#rules', function(e) {
  swal({
    html: true,
    title: '<b>Title</b>',
    text: '<b>Text</b>'
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<button id="rules">Rules</button>

But it shows this:

enter image description here

However it should be written Text as text!

So what's going wrong here? How can I solve this issue?


Solution

  • html is not a boolean option, it's a string of HTML. And in v1 it has been deprecated in favor of content.

    So you should write

    $(document).on('click', '#rules', function(e) {
         swal({ title:'<b>Title</b>', content:'<b>Text</b>'});
    });