Search code examples
javascriptbootstrap-4modal-dialog

Close all modals bootstrap


I would like to close all modals with a line of code, I have a code is like this:

closeModals() {

    $('#new-user').modal('hide');
    $('#new-project').modal('hide');
    $('#new-task').modal('hide');
}

But the problem is that I have more than 20 modals in my project, is there a way of closing all modals without repeating the id of each modal ? Thank you !


Solution

  • If you can add class to the element you can call just this.

    $('.my-modals').modal('hide');