JQuery IE9 image size?

This piece of code does not work in IE9. In HTML, I declare the width and height of the images, however when I run the code it notifies 0 instead of the size of the image specified in the attribute. Does anyone know how to fix this?

Works great in Chrome / Firefox

// Sets Default Size to a data attr
function saveImageDefaults() {
    $('#rightBlock img').each(function() {
        alert($(this).attr('width'));
    });
}

jQuery(document).ready(function(){

    // Resize Right Block
    $('#rightBlock').width($('#whiteBlockIn').width() - 270);


    // Save Images Default  Width / Height
    saveImageDefaults();
}
+3
source share
2 answers

I think it jQueryreturns the computed style that occurs when the element is rendered. However, IE has elem.currentStylewhich, as far as I remember, is different from elem.runtimeStyle(which is similar to getComputedStyle()).

So try this.currentStyle.widthto see what it returns

+3
source

If it worked in IE8, you can use

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

as a quick and dirty solution.

+1
source

All Articles