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,639
  • 4
  • 29
  • 47
Kamil Davudov
  • 351
  • 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
  • 190,436
  • 28
  • 232
  • 252