Display div content in Sweet Alert

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?