Twitter Bootstrap Modal - IsShown

情到浓时终转凉″ 提交于 2019-11-28 09:43:31

Answer for Twitter Bootstrap 3:

$("element").data()['bs.modal'].isShown

or

$("element").data('bs.modal').isShown

The answer is:

$("element").data('modal').isShown

On bootstrap 3.0.x

  $('#modal_Id').data().modal.isShown

or

  $('#modal_Id').data('modal').isShown

modal_id is the id of your modal

If you'd like a Bootstrap version 2 and 3 solution and would rather not hit the data (since it looks like the name already changed once)...

$(element).hasClass('in') (would be "faded in" or "visible"; a plus that it returns a boolean)

or

"false" === $(element).attr('aria-hidden') (so that's aria-hidden or visible as well. "true" for hidden in this case.)

See source from bootstrap 3.3.1 here:

this.backdrop(function () {
...
  that.$element
    .addClass('in')
    .attr('aria-hidden', false)
...

Again, that code is from 3.3.1. Can confirm this also works in 2.1.0. Duck sniffing [sic] is probably better in this case.

Answer for Bootstrap 4:

$("element").data('bs.modal')._isShown

As a function:

function isModalShown(modal) {
    var modalIsShown = (modal.data('bs.modal') || {})._isShown;
    return !(typeof modalIsShown === 'undefined' || !modalIsShown);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!