Reputation: 10828
How do I pass ID from <button>
into Bootstrap Modal. So I can use ID to get information from ajax to display in the Modal.
For example:
Button:
<button id="123" type="button" class="btn btn-sm" data-toggle="modal" data-target="#Testing">Edit</button>
Should I use shown.bs.modal
do this?
$("#Testing").on('shown.bs.modal', function () {
// How to get ID? id="??"
//Ajax
});
Upvotes: 0
Views: 528
Reputation: 87203
You can use event
object that is passed to the show.bs.modal
handler.
$('#Testing').on('show.bs.modal', function (event) {
var id = $(event.relatedTarget).attr('id');
});
event.relatedTarget
refers to the button that has triggered the modal open event.
Upvotes: 2