The assignment of events with on
jQuery is indicated to add events to dynamically created elements.
The best place to understand about the on
is in the own documentation from jQuery
Here are examples of how to use:
You can use the on as a synonym for the 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, for example:
$('#elemento-pai').on('click', '#elemento', function() {
});
You should then study the plugin you are using and see what Html it generates looks like. Find the parent element you want to assign the event to and do as in the second example. Remembering that you can use any selector to add the event, in the example I used the id selector ("#") only to illustrate.
That’s what I was trying to do but it didn’t work out. I tried to take the fancybox class as a parent, the element’s own father and nothing.
– dsantoro
You want to add a slide effect when closing the modal of the fancybox, that’s it?
– Marcus Vinicius