Jquery confirm on delete using noty js is not working

191 Views Asked by At

I want user to confirm delete once clicked delete button( with class .delete) I use Noty js and included its script src:

    <script src="{{asset('dashboard_files/plugins/noty/noty.min.js')}}"></script>

The delete button with class .delete:

   <button type="submit" class="btn btn-danger .delete"><i class="fa fa-trash"></i>Delete</button>

My Jquery function in app.blade to let user confirm delete or cancel:

 <script>
    $(document).ready(function(){
        $(document).on('click','.delete', function(e){
            e.preventDefault();
            var that = $this
            var n = new Noty({
                text:'Confirm deleting record',
                killer:true,
                buttons:[
                    Noty.button('yes', 'btn btn-danger mr-2', function(){
                        that.closest('form').submit()
                    }),
                    Noty.button('no','btn btn-danger',function(){
                        n.close()
                    }),
                ]

            })  //end of var n
            n.show();
        });  //end of onclick
    });  //end of ready fn
</script>

Deep thanks;

1

There are 1 best solutions below

1
clouddreams On

Your class name has a '.' in 'delete'. Change it to

<button type="submit" class="btn btn-danger delete"><i class="fa fa-trash"></i>Delete</button>

and it should work.