Mo J. Mughrabi
Mo J. Mughrabi

Reputation: 6997

bootstrap find and close open modals

am using bootstrap 2.3.2 to display modals with information, in some scenarios it will show error messages. As am trying to create a loosely-coupled functions, the error displaying function am trying somehow to make it find and close any open modals and then toggle the error modal.

jQuery.fn.AlertModal = function (message) {
    /**
     * AlertModal
     *
     * @param message
     * @returns None
     */

    var $ = jQuery,
        modal = $('#modal-alert');

    modal.on('hidden', function() {
        $(this).find('p.alert-message').html('');
    });

    modal.on('shown', function() {
        $(this).find('p.alert-message').html(message);
    });

    modal.modal('toggle');

};

any idea how i can do such a thing?

Thanks,

Upvotes: 0

Views: 61

Answers (1)

Paolo Casciello
Paolo Casciello

Reputation: 8202

Use a selector to find any modal in the page that doesn't have an .hide class and call its .modal('hide') method.

Upvotes: 2

Related Questions