This is the code I’m using to get all loaded images:
$("img").on('load', function() {
console.log('Image Loaded');
}).each(function() {
if(this.complete){
//$(this).trigger('load');
var img = $(this).attr('src');
console.log(img);
}
});
but it’s not working with those that are loaded with ajax afterwards, so I tried:
$(document).on('load', 'img', function(){
console.log('Image Loaded');
}).each(function() {
if(this.complete){
//$(this).trigger('load');
var img = $(this).attr('src');
console.log(img);
}
});
but it’s not doing anything, what would be the correct way? I need to manipulate the parent divs of each image that is freshly loaded, so getting just all images period on every ajax load would be overkill and not elegant
3
Answers
How about this?
I will suggest that you create a function for getting images and also call the same function after ajax execution.
Edit
Pass an
id
orclass
string present in document or returned ajax data to limit the scope of the functionThis is how I solved it:
Inside AJAX response.
I think it’s self explanatory, works perfectly!
In the checkPic functuion I find this element by the src and get the parent elements and so on.