Eugenio Segala Eugenio Segala - 1 year ago 105
jQuery Question

if img < 500 apply css

i have this code:

var jq111 = jQuery.noConflict();

jq111('.slides img').each(function(){
jq111self = jq111(this).height();
if(jq111self < 500){
jq111(this).addClass( "product-rescue" );

if an image is less than 500 px apply a CSS class.

But there is a problem, is not working properly, and is applied 1/3 to images larger than 500px.


Answer Source

you need to wait for the image to load:

var jq111 = jQuery.noConflict();

jq111('.slides img').on("load", function() {
    var jq111self = jq111(this);
    if(jq111self.height() < 500){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download