2018 Update - Using Bootstrap 4
I found that most of the answers seem to contain a lot of jQuery unnecessary. To open a modal from another modal, simply use the events provided by Bootstrap, such as "show.bs.modal". You may also want some CSS for handling background overlays. Here are 3 open modal options from another scenario ...
Open a modal from another modal (leave the 1st modal open)
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a> <div class="modal" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Modal title</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div><div class="container"></div> <div class="modal-body"> ... <a data-toggle="modal" href="#myModal2" class="btn btn-primary">Open modal2</a> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> <div class="modal" id="myModal2" data-backdrop="static"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">2nd Modal title</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div><div class="container"></div> <div class="modal-body"> .. </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> <a href="#" class="btn btn-primary">Save changes</a> </div> </div> </div> </div>
In this case, the potential problem is that the background from the 2nd modal hides the 1st modal. To prevent this, do a 2nd modal data-backdrop="static" and add some CSS to fix the background z-indexes.
.modal:nth-of-type(even) { z-index: 1052 !important; } .modal-backdrop.show:nth-of-type(even) { z-index: 1051 !important; }
https://www.codeply.com/go/NiFzSCukVl
Open modal from another modal (close 1st modal)
This is similar to the scenario described above, but since we close the 1st mod when the 2nd opens, there is no need to fix the CSS background. A simple function that processes the event of 2 show.bs.modal show.bs.modal closes the 1st modal.
$ ("# myModal2"). on ('show.bs.modal', function (e) {$ ("# MyModal1") modal ("hide").});
https://www.codeply.com/go/ejaUJ4YANz
Open modal inside another modal
The last scenario of multiple modals opens the 2nd modal inside the 1st modal. In this case, the markup for the second is placed inside the first. No extra CSS or jQuery required.
<div class="modal" id="myModal1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Modal title</h4> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> </div> <div class="container"></div> <div class="modal-body"> ... <a data-toggle="modal" href="#myModal2" class="btn btn-primary">Launch modal 2</a> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> <div class="modal" id="myModal2"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">2nd Modal title</h4> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> </div> <div class="container"></div> <div class="modal-body"> ... </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> <a href="#" class="btn btn-primary">Save changes</a> </div> </div> </div> </div> </div>
https://www.codeply.com/go/iSbjqubiyn