Callback when we use target information in bootstrap

I am working with a single page application. There are several buttons that open this modal object through a data target.

I need to press the API when this "MODAL" opens on the screen via any button click. (There are several buttons that can open this modal mode)

One very messy way is to attach an onclick event to each button. Can anyone suggest me a cleaner way to accomplish this in which I could probably attach some kind of event handler to the modal?

here is a dirty solution to my problem

<a data-target="#SomeModal" data-toggle="modal" href="#">
<button class="btn btn-success btn-lg" onclick="function_api_call();">
Click me</button>
</a>

      

+3


source to share


2 answers


You can listen to the modal show event:

$('#SomeModal').on('show.bs.modal', function (e) {
    // do something...
})

      



It will be called every time the modal is called, from the direct js call and from the data p> attribute

For reference (Bootstrap modal events list): http://getbootstrap.com/javascript/#modals-events

+9


source


add a class for the button for example: myModalButtonsClass and add an onclick event for this class instead of adding an onclick event for each button



$(".myModalButtonsClass").click(function(){ 


});

      

0


source







All Articles