-2

How to identify id of modal window in this JS

$('.modal-Goalkeepers, .modal-Defenders, .modal-Midfielders, .modal-Forwards').on('show.bs.modal', function (data) {

   var id = {{here I want to know id of modal is now shown}}

});
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Igor Ostapiuk
  • 589
  • 3
  • 7
  • 23

2 Answers2

0

you can try this :

$('.modal-Goalkeepers, .modal-Defenders, .modal-Midfielders, .modal-Forwards').on('show.bs.modal', function(data) {

  var id = $(this).attr('class');
});

an example :

$('.block1,.block2,.block3').click(function() {

  alert($(this).attr('class'));

});
.block1,.block2,.block3 {
height:100px;
margin:20px;
background:#000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div  class="block1"></div>
<div  class="block2"></div>
<div  class="block3"></div>

UPDATE : he need to get the class and not the id !

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
0

Since you are using jQuery, you can access the ID through the keyword 'this'. This will access the element that is being called by the event.

$(this).attr('id');
Korio
  • 84
  • 3