Twitter bootstrap modal-backdrop doesn't disappear-open source projects jschr/bootstrap-modal
Bill Huertas
I just spent way too long on this problem 🙂
While the other answers provided are helpful and valid, it seemed a little messy to me to effectively recreate the modal hiding functionality from Bootstrap, so I found a cleaner solution.
The problem is that there are a chain of events that happen when you call
$("#myModal").modal('hide');
functionThatEndsUpDestroyingTheDOM()
When you then replace a bunch of HTML as the result of the AJAX request, the modal-hiding events don’t finish. However, Bootstrap triggers an event when everything is finished, and you can hook into that like so:
$("#myModal").modal('hide').on('hidden.bs.modal', functionThatEndsUpDestroyingTheDOM);
Hope this is helpful!