GOAL:
Red borders should became green once image in .thumbnail
div is loaded
JSFIDDLE: https://jsfiddle.net/3k8xy2cf/
var container;
var img;
$("#products .thumbnail").each(function() {
container = $(this);
img = new Image();
img.src = $(container).find('img').attr('src');
img.onload = function() {
$(container).addClass('loaded');
}
});
.product {
float: left;
border: 5px solid red;
}
.product.loaded {
border-color: green;
}
.product img {
width: 25%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="products">
<div class="product">
<div class="thumbnail">
<img src="https://placehold.it/600x600" alt="">
</div>
</div>
<div class="product">
<div class="thumbnail">
<img src="https://placehold.it/800x800" alt="">
</div>
</div>
</div>