Ceejay
Ceejay

Reputation: 7267

How to close one modal popup when another one is active

I am trying to get a modal popup window from another modal popup window. when i click the link from the first popup window, the second popup window is opening, but the first one not getting closed.

How can i do this?

jQuery:

 $(".get-me-license").click(function(){
    $("#license").modal('show');
 });

 $(".confirm-my-license").click(function(){
    $("#confirm-license").modal('show');
 });

HTML:

<div id="license" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                  <img class="modal-cont" src="images/license-popup.png">

                <table class="get-license-confirm"> 
                  <tr>
                    <td><a href="#" class="btn btn-warning confirm-my-license">GET LICENSE</a></td>
                  </tr>
                </table>

                </div>                
            </div>
        </div>
 </div>
 <div id="confirm-license" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                  <img class="modal-cont" src="images/license-popup.png">

                <table class="get-license-confirm"> 
                  <tr>
                    <td><a href="#" class="btn btn-warning">Confirm</a></td>
                  </tr>
                </table>

                </div>                
            </div>
        </div>
 </div>

Upvotes: 1

Views: 3141

Answers (2)

Sumit Jha
Sumit Jha

Reputation: 368

put common class in all modal and just call modal funtion with hide argument befor show new modal. Like this :

suppose common class for modal is "common-modal".

$('.common-modal').modal('hide');

then

$('yourmodal').modal();

Upvotes: 0

Germanaz0
Germanaz0

Reputation: 914

You can try this two methods

To hide the modal:

$('.YourModalElement').modal('hide');

Or to totally destroy the modal instance, you can try this one:

$('.YourModalElement').data('modal', null);

Upvotes: 2

Related Questions