6

I am using this in my application. I would like to use sweet alert like below.

swal({
    title: "Are you sure?",
    text: "You are going to delete <b>"+ name +"</b> address. ",
    icon: "warning",
    buttons: true,
    dangerMode: true,
   })

But it now working. It is displaying HTML code. Thanks.

Update

I read this question, but this question is about sweet alert2. My question is about sweet alert . Both are sweet alert but both are not same.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
abu abu
  • 6,599
  • 19
  • 74
  • 131

2 Answers2

9

As @Elnoor has mentioned you can try to use html, but I had a problem in SWAL2 with it so I have used the innerHTML. Like :

 var myhtml = document.createElement("div");
 myhtml.innerHTML = "You are going to delete <b>"+ name +"</b> address. ";

And then put it in your content in swal like :

swal({
    title: "Are you sure?",
    content: myhtml,
    icon: "warning",
    buttons: true,
    dangerMode: true,
   })

Mark that i changed text tag to content tag.

SupremeDEV
  • 384
  • 1
  • 15
8

Sweet Alert 2: Instead of text use html. For more check here.

Sweet Alert: In older version of sweet alert they don't use html object any more, instead you can use content object as shown here. And in your case you can create an element then embed your html inside that element and add it to swal's content object like below. (Fiddle here)

var elem = document.createElement("div");
elem.innerHTML = "Hello <br> <strong>World<strong> ! <hr>";

swal({
  content: elem,
});
Elnoor
  • 3,401
  • 4
  • 24
  • 39
  • Thanks @Elnoor. But your solution is for https://sweetalert2.github.io. I need solution for https://sweetalert.js.org. Thanks. – abu abu Apr 10 '18 at 10:15
  • sorry friend, i have missed that part of your question. You answer is exactly what @SupremeDEV explained here https://stackoverflow.com/a/49747702/5435780 – Elnoor Apr 10 '18 at 15:45