I am trying to get the clicked element using the property relatedTarget
of the show.bs.modal
event. It's always getting undefined though.
This is what I have:
$("#curCarSelect").on('click', function(e) { $("#curCarModal").on('show.bs.modal', function(event) { modalOpenedby = event.relatedTarget; alert(modalOpenedby); }).modal('toggle'); });
try:
$("#curCarSelect").on('click', function(e) { $modal.modal('toggle', $(this)); });
where $modal is your modal element to open, then:
$modal.on('show.bs.modal', function (event) { var button = $(event.relatedTarget) // Button that triggered the modal })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With