Sweetalert: How to post HTML in SWAL

Created on 13 Nov 2017  路  2Comments  路  Source: t4t5/sweetalert

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"
}
}
});`

Most helpful comment

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.

All 2 comments

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"
                }
            }
        })

`

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rapeflower picture rapeflower  路  4Comments

voodoo6 picture voodoo6  路  4Comments

girishbr picture girishbr  路  5Comments

AlexV525 picture AlexV525  路  4Comments

mateuszjarzewski picture mateuszjarzewski  路  4Comments