0

So here is a question.

I have HTML

<a class="callback">Callback</a>

I have external Jquery-file (with Bootstrap.js included)

$(".callback").on('click', function() {
var myModal = '<div><a id="callback"></div>';
$(myModal).modal('show');
});
$("#callback").on('click', function() {
//some actions
});

So ".callback"-event works fine because that link we have in the current DOM. But "#callback"-event does NOT work. Maybe cos of that element appears after JS-file has loaded (seriously?).

Please, could anyone answer why "#callback"-event does NOT work?

Thanks a lot!

daniula
  • 6,790
  • 4
  • 31
  • 49
Kamil Davudov
  • 361
  • 1
  • 3
  • 14

1 Answers1

0

You need to use jQuery's event delegation syntax for on() when binding to dynamically created elements:

$(document).on('click', "#callback", function() {
j08691
  • 197,815
  • 30
  • 248
  • 265