Categories
JavaScript Answers

How to display HTML code in text with sweet-alert and JavaScript?

Spread the love

Sometimes, we want to display HTML code in text with sweet-alert and JavaScript.

In this article, we’ll look at how to display HTML code in text with sweet-alert and JavaScript.

How to display HTML code in text with sweet-alert and JavaScript?

To display HTML code in text with sweet-alert and JavaScript, we can use the Swal.fire method.

For instance, we write

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

to add the sweet-alert 2 script tag.

Then we write

Swal.fire({
  title: "<i>Title</i>",
  html: "Test: <b>test</b>",
  confirmButtonText: "<u>OK</u>",
});

to call Swal.fire with an object with the title, html content, and the confirmButtonText content of the alert box.

Conclusion

To display HTML code in text with sweet-alert and JavaScript, we can use the Swal.fire method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.