Modal it is open multiple times

1.3k Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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
        }
    });
});