Enable Javascript within a Fancybox

Asked

Viewed 141 times

2

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

1 answer

1

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.

  • 1

    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.

  • 1

    You want to add a slide effect when closing the modal of the fancybox, that’s it?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.