Skip to content
Advertisement

Wrap is not working on dynamically loaded element. Why?

The wrap(); works well on its own, but when it is called after the load();, it doesn’t.

What could be done to make it work? I tried to put the wrap(); code inside a separate .js file, but that didn’t work. I also tried to load the wrap(); inside: $( window ).on( "load", function() { ... }) and then place it inside the footer of the html, which didn’t solve the problem either.

Here is my code:

JavaScript
JavaScript
JavaScript

Edit 1# & 2#:

I need to wrap each .gallery-items of the #gallery-1 after it loaded from https://webhelytervezo.hu/ into the #partner div of page with the .page-id-202 class (https://webhelytervezo.hu/en/) and the page with the class .page-id-201 (https://webhelytervezo.hu/en/). The code works only on the main page (where the content is not loaded but there without needed to be loaded).

Edit 3#

Now the code is:

JavaScript

How can I simplify it?

Advertisement

Answer

Load is asynchronous function. Put your code inside callback function of the load method.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement