Enable Javascript within a Fancybox

2

I need to make a slideToggle in a Fancybox window. The normal method of catching (elemento).click(functiom(){...}) I know it does not work. I only know that we should use .on() of jQuery but I do not know how to do it and anyone who knows would like a brief explanation or link to good content regarding it. Thank you.

    
asked by anonymous 01.05.2015 / 19:38

1 answer

1

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.

    
01.05.2015 / 20:03