2

I'm using bootbox library. I have one button called Delete.

$('body').on("click", ".deleteDiagnostic", function () {
        var id = $(this).attr("data-diagnosticID");
        var currentRow = $(this).closest('tr');
        bootbox.confirm("Are you sure want to delete?", function (result) {
            if (result == true) {
                //code here
            }
        });
});

I'm also using PartialView and the page which contains button is loaded dynamically. Sometimes when I click, bootbox is open multiple times and I don't know why.

PS: When I load PartialView for first time it's working perfectly, but when I load PartialView multiple times, then bootbox appears multiple times on button click.

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128

1 Answers1

5

Please try to modify your code like this:

$('body').on("click", ".deleteDiagnostic", function (evt) {
    evt.stopImmediatePropagation();

    var id = $(this).attr("data-diagnosticID");
    var currentRow = $(this).closest('tr');
    bootbox.confirm("Are you sure want to delete?", function (result) {
        if (result == true) {
            //code here
        }
    });
});
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
Martino Lessio
  • 775
  • 1
  • 9
  • 17