0

For some reason changing the format of the below jQuery event handler code for a larger .js file seems to make the on click event work, but technically both ways should be valid.

$('[data-onclick="flyTo"], [data-onclick="flyToAndClick"], [data-onclick="flyToThenClick"], [data-onclick="flyToAndAction”]’).on(‘click’, function(e) {

vs

$(document).on('click', '[data-onclick="flyTo"], [data-onclick="flyToAndClick"], [data-onclick="flyToThenClick"], [data-onclick="flyToAndAction"]', function(e) {

This seems like such a trivial change, but I really want to understand what's happening here.

Cheers for any help!

ged12345
  • 9
  • 1
  • 1
    Replace all `“` and `”` by `"`, and all `‘` and `’` by `'`. Both statements have different meanings. Are the selected elements always the same or are they dynamically changed? The second snippet uses event delegation, the first one does not. – Sebastian Simon Jan 17 '23 at 23:27
  • 2
    See also the [official jQuery documentation](//api.jquery.com/on#direct-and-delegated-events). – Sebastian Simon Jan 17 '23 at 23:38

0 Answers0