Examples show an alert of SweetAlert

Example 1: Alert basic Hello world. Use 1 parameter:

 

<!DOCTYPE html>

<html>

    <body>

        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

        <p>Example Hello world</p>

 

        <button onclick="run()">Run</button>

 

        <script>

            function run() {

                swal("Hello world!");

            }

        </script>

 

    </body>

</html>

 

 Result:

 

 

Example 2: Alert have title and text. Use 2 parameter

 

<!DOCTYPE html>

<html>

    <body>

        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

        <p>Example Alert with Title and Text</p>

 

        <button onclick="run()">Run</button>

 

        <script>

            function run() {

                swal("Here's the title!", "...and here's the text!");

            }

        </script>

 

    </body>

</html>

 

Result:

 

 

 

Example 3: Alert with an icon alert. There are 4 predefined ones: "warning", "error", "success" and "info". Use 3 parameter

 

<!DOCTYPE html>

<html>

    <body>

        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

        <p>Example Alert with Title and Text</p>

 

        <button onclick="run()">Run</button>

 

        <script>

            function run() {

                swal("Good job!", "You clicked the button!", "success");

            }

        </script>

 

    </body>

</html>

 

Result: