7

I have a button, like so:

<a data-toggle="modal" href="#influencerModal" class="btn btn-primary influencer-card">Influencer Profile</a>

When I click it, I want the modal to not open, so that I can ajax some content into it, then manually open it with .modal().

Not seeing many helpful items online about this idea of stopping it AFTER the button to open it has been clicked.

Any questions, just ask below.

2 Answers2

10

Remove data-toggle="modal attribute from :

<a data-toggle="modal" href="#influencerModal" class="btn btn-primary influencer-card">Influencer Profile</a>

Instead add onclick="function_call()" attribute, so that you can call AJAX in that JS function. After AJAX success you can open model like below :

$('#your_modal_id').modal("show");

You can refer SO question.

Also refer w3schools.com page.

Community
  • 1
  • 1
AkshayP
  • 2,141
  • 2
  • 18
  • 27
  • Make sure you're binding the "on click" through JavaScript. Dont just put the onclick attribute on the html element. Doing the html way is generally considered bad practice. – James Collier Jun 16 '16 at 04:04
3

Remove this attribute from the link data-toggle="modal"

Then use this in the script wherever you want the modal to be triggered

$('#modal').modal("show")
Joshua Belarmino
  • 546
  • 9
  • 24