How to get width of a div in pixels using JQuery (IE)

Posted by Casidiablo on Stack Overflow See other posts from Stack Overflow or by Casidiablo
Published on 2010-04-21T21:03:09Z Indexed on 2010/04/21 21:13 UTC
Read the original article Hit count: 259

Hello there.

At first glance it sounds easy... when using JQuery one can use the .width() method to retrieve the width of an element. The problem comes when the DIV element does not have its size in pixels but in words like 'auto' or 'inherit'.

When I do this it works nice in Firefox and Chrome even if the size is specified in words:

alert($('#id_div').css('width')); // these two sentences does not

It returns something like: 96px. But, IE returns the word 'auto'. I need to know the size it has in pixels because I have to do some calculations with that number... so, I've been wondering how to solve this problem. How can I solve this issue?

Thanks for reading.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui