Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal relatedTarget is undefined

Tags:

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');   }); 
like image 644
user3312508 Avatar asked Oct 03 '14 21:10

user3312508


1 Answers

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 }) 
like image 180
Antonio Avatar answered Sep 20 '22 16:09

Antonio