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,898
  • 4
  • 32
  • 49
Kamil Davudov
  • 363
  • 1
  • 3
  • 15

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
  • 204,283
  • 31
  • 260
  • 272