TK123 TK123 - 6 months ago 45
Javascript Question

Twitter Bootstrap Modal Event Not Fired When Modal is Shown

According to the docs:

http://getbootstrap.com/javascript/#modals

It should fire the methods "show.bs.dropdown" and "shown.bs.dropdown". But it doesn't:

http://jsfiddle.net/mQunq/3/

HTML:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">Hello world</div>
</div>
</div>


jQuery:

// show.bs.modal doesn't work either

$('#myModal')
.modal('show')
.on('show.bs.modal', function() {

alert('shown baby!');

});

Answer

Youe need first register event then trigger it

$('#myModal')
    .on('show.bs.modal', function() {

        alert('shown baby!');

    }).modal('show');

jsfiddle

Comments