Hryhorii
Hryhorii

Reputation: 1243

How destroy Boostrap 3 modal dialog from DOM

I call content for modal dialog from ajax

 $.ajax({
    url: "/Clerk/PauseServiceDialog",
    success: function (data) {
        $("body").append(data);
        $("#pauseServiceDialog").modal({ keyboard: false });
    }
});

When I close modal I use this code

  $(document).on('hidden.bs.modal', ".modal", function (e) {
    this.remove();
});

In firebug I see html code is deleted. But if I again call dialog and use some event I get 2 event. How I understand modal dialog do not correct deleted from DOM.

Upvotes: 0

Views: 87

Answers (2)

Hryhorii
Hryhorii

Reputation: 1243

I found answer how fix duplicate event.

 $(document).on('hidden.bs.modal', ".modal", function (e) {
    var name = "#" + $(this).find("button.btn-primary").attr("id");
    $("body").off("click", name);
    $(this).remove();
});

Upvotes: 1

Vasiliy vvscode Vanchuk
Vasiliy vvscode Vanchuk

Reputation: 7159

You can hide modal by code

   $("#pauseServiceDialog").data('bs.modal').hide()

P.S. sorry, i didn't understand notation $(document).on('hidden.bs.modal' in general - you should delete modal element AND object which handle its events ( it stored at $("#pauseServiceDialog").data('bs.modal') )

Upvotes: 0

Related Questions