John Smith
John Smith

Reputation: 91

IE9 jQuery Image Size?

This code snippet doesn't work on IE9. In the HTML I declare the width and the height of images, however when the code runs it alerts 0 instead of the image sized specified in the attribute. Does anyone know how to fix this?

Works fine on 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();
}

Upvotes: 3

Views: 993

Answers (2)

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19049

I think jQuery is returning the computed style, which is when the element is rendered. However, IE has elem.currentStyle which - as far as I can remember - differs from elem.runtimeStyle (which is similar to getComputedStyle()).

So, try this.currentStyle.width to see what it returns

Upvotes: 3

silex
silex

Reputation: 4320

If it was working in IE8, you can use

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

as quick and dirty solution.

Upvotes: 1

Related Questions