pop up modal on button click bootstrap 4 code example

Example 1: bootstrap pop modal from another modal

// Hide current modal before opening new one
$("#idModal").modal('hide');
$("#idModal2").modal() // or .modal("show");

// show 1st modal again after closing 2nd modal
$("#idModal2").on('hidden.bs.modal', () => $("#idModal").modal('show'))
// using hide.bs.modal might cause modal to stop scrolling!!!

Example 2: bootstrap 4 start modal in modal

var modal_lv = 0;
$('.modal').on('shown.bs.modal', function (e) {
    $('.modal-backdrop:last').css('zIndex',1051+modal_lv);
    $(e.currentTarget).css('zIndex',1052+modal_lv);
    modal_lv++
});

$('.modal').on('hidden.bs.modal', function (e) {
    modal_lv--
});