hi everyone,

i want to display content of div into sweet alert message and here is my code

<?php 

echo '<script>
var swal2container = $("#swal2container").text();

setTimeout(function() {
swal({
title: "Alert!",
text: swal2container,
type: "error"
}, function() {
window.location = "index.php";
});
}, 100);




</script>';


?>

<div id="swal2container">test</div> 

i still cant get the content of swal2container when sweet alert . Anyone can help meh?

Sorry, I just saw this now. Do you mind sharing the solution so it could help other people in the future?

Based on the code I am seeing, I would expect that after var swal2container = $("#swal2container").text(); the value of swal2container would be test. You're saying it wasn't?

i use another way by using html in sweetalert2 :

Swal.fire({

    title: 'xx',
    html:
    '<table width="100%" style="font-family:arial;" align="center">' +
    '<tr align="center">' +
    '<td width="50%">' +
    '<div align="left">xx</div> ' +
    '</td>' +
    '<td width="5%">' +
    '<div align="center">:</div> ' +
    '</td>' +
    '<td width="40%">' +
    '<div><strong>'+div+'</strong></div> ' +
    '</td>' +
    '</tr>' +


    '<tr align="center">' +
    '<td>' +
    '<div align="left">xx</div> ' +
    '</td>' +
    '<td width="5%">' +
    '<div align="center">:</div> ' +
    '</td>' +
    '<td width="40%">' +
    '<div><strong>xx</strong></div> ' +
    '</td>' +
    '</tr>' +


    '</table>'

which i think give me the same result

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.