Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Overlay background color of sweet alert 2

I have recently moved sweet alert 1 to sweet alert 2, but based on the documentation there is no option for theming the overlay background of an alert box like sweet alert 1

.swal-overlay {
  background-color: rgba(43, 165, 137, 0.45);
}.

Please how can I achieve changing the overlay background of sweet alert 2?

like image 750
Eshiett Oto-obong Avatar asked Sep 12 '25 00:09

Eshiett Oto-obong


2 Answers

Swal.fire({
  icon: 'success',
  background: 'red',
})
like image 132
Khalil Ibrahim Avatar answered Sep 13 '25 15:09

Khalil Ibrahim


To achieve this you can just use jQuery selectors and select the overlay element like so.

<button type="button" onclick="opentheSwal();">OK</button>
<script>
    function opentheSwal() {
        swal(
            'Good job!',
            'You clicked the button!',
            'success'
        );
        $(".swal2-modal").css('background-color', '#000');//Optional changes the color of the sweetalert 
        $(".swal2-container.in").css('background-color', 'rgba(43, 165, 137, 0.45)');//changes the color of the overlay
    }
</script>

You will have to select the .swal2-container.in to change the overlay and apply the css using jqueries .css() function.

Good Luck.

like image 35
Hayden Passmore Avatar answered Sep 13 '25 15:09

Hayden Passmore