Showing posts with label Modal Popup. Show all posts
Showing posts with label Modal Popup. Show all posts

Sunday, September 29, 2019

bootstrap, Modal - How to get Bootstrap Modal's invoke or source element?

How to get Bootstrap Modal invoke or source element?

$('#your-modal').on('show.bs.modal', function (e) {
  var $invoker = $(e.relatedTarget);
});

Various events of modal popup are:


  1. show.bs.modal: fired just before the modal is open.
  2. shown.bs.modal: fired after the modal is shown.
  3. hide.bs.modal: fired just before the modal is hidden.
  4. hidden.bs.modal: fired after the modal is closed.

How to open a Bootstrap modal window using jQuery?


$('#myModal').modal('show') // initializes and invokes show immediately

Bootstrap has a few functions that can be called manually on modals:

$('#myModal').modal('toggle');

You can check more documentation here
https://getbootstrap.com/docs/3.4/javascript/

$('#myModal').modal('show');
$('#myModal').modal('hide');