Determine which button opened a Bootstrap 3 modal
I have the following Bootstrap buttons:
<button type="button" class="btn btn-primary btn-lg" data-button="create" data-toggle="modal" data-target="#modal">Create</button> <button type="button" class="btn btn-primary btn-lg" data-button="delete" data-toggle="modal" data-target="#modal">Delete</button>
and this is the modal:
How can I figure out which button triggered the modal to open?
Specifically, I need the
You can listen to either of the
Within the function, the event has a
relatedTarget property attached to it. You can use this to determine which button triggered the modal to open.
This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the
relatedTargetproperty of the event.
.. and if you want to access the
data-button attribute, use:
Conversely, if you want to determine which button caused the modal to close, see this answer.