Function for determining the loading of DOM and images in an AJAX call .load

I use the function to dynamically load content through Ajax using this method:

$("#content").load('file.html', function(response, status, xhr){
     alert('test');
});

A warning is loaded when the request is successful, but before any images are uploaded. Is there any function that I can use to trigger after all the images (in file.html) are loaded and the DOM is completely ready? I tried the usual one, for example $ (window) .load and $ (document) .ready, but this obviously did not work, which makes sense.

Edit for future reference: To clarify, I used skrollr for uploaded content. Since this plugin adapts the height of the body based on the loaded content, it is poorly confused with ios devices. Using this function, I can make sure that the skrollr instance is not updating too early.

+4
source share
2 answers

You can use jquery plugin, try using ajax callback function when loading contents, see below code example imagesloadeddone

$("#content").load('file.html', function(response, status, xhr){
     $("#content").imagesLoaded( function(){
          alert('test');
     });

});
+2
source
0

Source: https://habr.com/ru/post/1569984/


All Articles