0

Here is the code I'm trying to use :

$(document, ".openScript").on("click", function() {
    $("#scriptWindow").modal("show");
});

This will call the event at any click. But because the .openScript isn't present at the beginning, if I do like below once, it won't be attached to the element that will be created after this code :

$(".openScript").on("click", function() {
    $("#scriptWindow").modal("show");
});

I thought it was possible to do like the first example, is there no other way than calling the second code at any time I create an element that has the .openScript class ?

Elfayer
  • 4,411
  • 9
  • 46
  • 76

1 Answers1

2

Reference - .on()

.on( events [, selector ] [, data ], handler )

Following is the correct delegation syntax.

$(document).on("click", ".openScript", function() {
    $("#scriptWindow").modal("show");
});
Shaunak D
  • 20,588
  • 10
  • 46
  • 79