Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sweet-alert display HTML code in text

I am using sweet-alert plugin to display an alert. With a classical config (defaults), everything goes OK. But when I want to add a HTML tag into the TEXT, it display <b>...</b> without making it bold. After searching for the answer, it looks like I don't have the right search word...

How to make sweet alert display the text also with HTML code?

var hh = "<b>test</b>"; swal({     title: "" + txt + "",      text: "Testno  sporocilo za objekt " + hh + "",       confirmButtonText: "V redu",      allowOutsideClick: "true"  }); 
like image 752
Peter Avatar asked Nov 10 '14 07:11

Peter


People also ask

How do I show sweet alert in html?

All you have to do is enable the html variable to true.. I had same issue, all i had to do was html : true , var hh = "<b>test</b>"; swal({ title: "" + txt + "", text: "Testno sporocilo za objekt " + hh + "", html: true, confirmButtonText: "V redu", allowOutsideClick: "true" });

How do I show sweet alert?

There are two ways to create a sweet alert using the Swal. fire() function. You can either pass the title, body text, and icon value in three different arguments, or you can pass a single argument as an object with different values as its key-value pairs.

How do I show a message in html?

The Window alert() method is used to display an alert box. It displays a specified message along with an OK button and is generally used to make sure that the information comes through the user. It returns a string which represents the text to display in the alert box.


1 Answers

The SweetAlert repo seems to be unmaintained. There's a bunch of Pull Requests without any replies, the last merged pull request was on Nov 9, 2014.

I created SweetAlert2 with HTML support in modal and some other options for customization modal window - width, padding, Esc button behavior, etc.

Swal.fire({   title: "<i>Title</i>",    html: "Testno  sporocilo za objekt: <b>test</b>",     confirmButtonText: "V <u>redu</u>",  });
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
like image 61
Limon Monte Avatar answered Sep 20 '22 23:09

Limon Monte