I have an ajax call returning html code which is inserted into a container.
Now I need to call a jQuery function to format the gallery, but I can't find a way to ensure that the jQuery function waits for returnedData to be fully loaded/rendered.
As you can see I have tried .ready() but it doesn't work. I have also tried setTimeout, which actually works, but as the returnedData can contain a lot of images, I can't use it as I don't know how long it would take to load all the images.
Any ideas?
$(document).ready(function() {
$.ajax(url, {type: 'POST', dataType: 'json', data: data, success: success_handler});
});
function success_handler(returnedData) {
$('.category-images-js').html(returnedData);
$('.category-images-js').ready(function() {
// Code to run after all data inside returnedData is fully ready/rendered
);
}
SOLUTION: This thread: How to know if all elements in a DIV have been fully loaded? worked for me but I had to make a work-around as the code I run, when data inside returnedData is fully ready/rendered, makes the on load trigger 3 times per image.