Event assignment with on
fault of jQuery is indicated to add events to dynamically created elements.
The best place to understand about on
is jQuery's own documentation
Here are examples of how to use:
You can use on as a synonym for click
, as follows:
$('#elemento').on('click', function() {
});
But this does not work for dynamically created elements (as should be the case with Fancybox). To work with such elements, you must configure the event from a parent element of the element you want to add the event to, for example:
$('#elemento-pai').on('click', '#elemento', function() {
});
You should then study the plugin you are using and see what the Html it generates. Look for the parent element to which you want to assign the event and do as in the second example. Remember that I can use any selector to add the event, in the example I used the id selector ("#") just to illustrate.