why jquery confirmation ins not working

1.3k Views Asked by At

am trying to get best confirmation why jquery is not working what went wrong am not getting confirmation dailog box

Fiddle: https://jsfiddle.net/trso8x65/

<html>
     <head>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.js"></script>
     </head>
     <body>

      <button type="button" class="confirm">click me </button>
    <script>
      $.confirm({
        title: 'Confirm!',
        content: 'Simple confirm!',
        buttons: {
            confirm: function () {
                $.alert('Confirmed!');
            },
            cancel: function () {
                $.alert('Canceled!');
            },
            somethingElse: {
                text: 'Something else',
                btnClass: 'btn-primary',
                keys: ['enter', 'shift'],
                action: function(){
                    $.alert('Something else?');
                }
            }
        }
    });
    </script>
     </body>
    </html>
4

There are 4 best solutions below

7
On
0
On

You possibly have other issues (as noted, you don't seem to be loading jQuery, on which jQuery.confirm depends, and that should trigger a very clear error message in the JavaScript console) but the main problems is that you never link your button with the plug-in:

<button type="button" class="confirm">click me </button>
$.confirm();

Right from the project page:

<a href="home" class="confirm">Go to home</a>
$(".confirm").confirm();

In other words, you need to call the plugin on an jQuery object with a proper selection.

1
On

This is how it should work basically

 <html>
 <head>
   <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
   <link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.css" rel="stylesheet">
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.js"></script>
 </head>
 <body>
  <button class="btn btn-primary" id="complexConfirm">Click me</button>


   <script>


   $("#complexConfirm").confirm({
    title: 'Confirm!',
    content: 'Simple confirm!',
    buttons: {
        confirm: function () {
            $.alert('Confirmed!');
        },
        cancel: function () {
            $.alert('Canceled!');
        },

    }
});

   </script>
 </body>
</html>
0
On

You are missing jQuery Library .

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

It Must Be Very First Library Under Head Section .