How to make sweetalert works for your button

918 views Asked by At

Here my small mail sender.

I liked how sweetalert work, so I decided to go for it. Here is where I took the infos.

I downloaded everything necessary. Made the due calls as they suggest. I believe everything should be okay so far, even if they made one call on their source code different than those suggested. Where I believe my problem lies is on the js code snippet they advise to use. Well, actually the just wrote "Call the sweetAlert-function after the page has loaded" so I assumed it should be some code between <script></script> tags. At fist glance it seems a too simple piece of code.

<script>document.querySelector('ul.examples li.success button').onclick = function(){swal("Good job!", "You clicked the button!", "success");};</script> is what they use to make the alert I am interested in works in their page's source code.

Where am I doing wrong? Anyone willing to help? Thank you :)

1

There are 1 answers

6
David Tansey On

Make sure that your page is loading the javascript and css that are required for SweetAlert.

A simple functional snippet, using SweetAlert assets from a CDN is posted here.

swal("Good job!", "You clicked the button!", "success");
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.0.1/sweetalert.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.0.1/sweetalert.min.css">