I\'ve made use of modal window for a wizard implementation which has around 4,5 steps. I need to destroy it completely after the last step(
If modal shadow remains darker and not going for showing more than one modal then this will be helpful
$('.modal').live('hide',function(){
if($('.modal-backdrop').length>1){
$('.modal-backdrop')[0].remove();
}
});
$('#myModal').on('hidden.bs.modal', function () {
$(this).data('bs.modal', null).remove();
});
//Just add .remove();
//Bootstrap v3.0.3
My approach would be to use the clone() method of jQuery. It creates a copy of your element, and that's what you want : a copy of your first unaltered modal, that you can replace at your wish : Demo (jsfiddle)
var myBackup = $('#myModal').clone();
// Delegated events because we make a copy, and the copied button does not exist onDomReady
$('body').on('click','#myReset',function() {
$('#myModal').modal('hide').remove();
var myClone = myBackup.clone();
$('body').append(myClone);
});
The markup I used is the most basic, so you just need to bind on the right elements / events, and you should have your wizard reset.
Be careful to bind with delegated events, or rebind at each reset the inner elements of your modal so that each new modal behave the same way.
If you have an iframe in your modal, you can remove its content by the following code:
$('#myModal').on('hidden.bs.modal', function(){
$(this).find('iframe').html("");
$(this).find('iframe').attr("src", "");
});
I don't know how this may sound but this work for me...........
$("#YourModalID").modal('hide');
Single line complete removal on hide ( ES6 )
$("#myModal").on('hidden.bs.modal', (e)=>e.currentTarget.remove());