Jquery simplemodal close existing modal and open a new one?

Matthew picture Matthew · Apr 27, 2010 · Viewed 11k times · Source

Alright, so all modals already have an image at the top right to close them. How can I make additionally another anchor to do the same thing? I thought I could use the "closeClass" option which default to "simplemodal-close" and just add that class to an anchor, but it didn't have the desired effect. Is that what I'm supposed to do? Also, all modals will have a "contact us" link which should close it's own modal and open the contact modal. How can I wait until it is closed to open the next one?

Ideas?

$('a#ask').click(function(){
        $.modal.close(function(){
        });
        $('#modal-contact').modal();
    });

Answer

Eric Martin picture Eric Martin · Apr 27, 2010

1) If you assign simplemodal-close to an element that is in the dialog content, SimpleModal will automatically bind the close function to click event for that element.

2) There are a number of ways you could do this, either by swapping out the content or first closing the dialog with $.modal.close(); then opening a new one.

UPDATE

$('a#ask').click(function(){
    $('#modal-contact').modal({onShow: function (dialog) {
        // handle the close yourself.
        // Don't use the closeClass on this element
        // call $.modal.close(); when you are done
        // call a function to open a new modal
    });
    return false;
});