t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

How to post HTML in SWAL #766

Closed jibboo closed 6 years ago

jibboo commented 6 years ago

I want to put HTML into my text parameter, but I get stuff like this:

This is a bold sentence.

It actually shows the html tags instead of rendering the html. I have tried putting the html in the 'text' paramater, 'content' parameter and 'html' parameter. None work. Help

`var msg = $("

").html("

User is not logged in or user's session has expired.

Please log in to continue.

");

swal({
icon:"warning", title:"Unable to validate user.", content: msg, buttons: { login: { text:"Login", value:"Login" } } });`

jibboo commented 6 years ago

OK, ... I was able to display HTML by doing it direct through javascript, but it does not work when using jQuery (as above).

` var msg = document.createElement("div"); msg.innerHTML = "

Either user is not logged in or user's session has expired.

Please log in to continue.

";

    swal({  icon:"warning",
            title:"Unable to validate user",
            content: slider,
            buttons:{ 
                login: {
                    text:"Login",
                    value:"Login"
                }
            }
        })

`

t4t5 commented 6 years ago

You'll have to create your DOM nodes using content. We might make this easier to do in the future using the React plugin for example.