Insert bs modal on page just by using JS

85 views Asked by At

I am trying to create a wrapper function for Bootstrap Modal, I have gone through the actual modal function definition but I am unable to figure out how to instantiate a Modal by using JS.

HTML:

<div class="modal"></div> <!--I DON'T WISH TO HAVE ANYTHING ELSE ON THE PAGE-->

JS:

var BSModal = {};

BSModal.create = function(options) {
  var modal = new Modal($('.modal'), options);  //THROWS ERROR, Modal not defined.

  ...

}.bind(BSModal);

How do I properly instantiate the modal? What am I doing wrong?

1

There are 1 answers

0
iurii On

According to https://github.com/twbs/bootstrap/blob/master/js/modal.js

$.fn.modal.Constructor = Modal

so i believe you can use something like this in your code

var modal = new $.fn.modal.Constructor($('.modal'), options);