views:

249

answers:

2

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')); 

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....

A: 

Try alert($('#id_div').width());

setrul
I also have tried that and it returns the same in IE. Thanks anyway.
Cristian
Sorry, that way worked perfectly. I had tried that, but the 'amazing' IE cache was still using the older script. Thanks!
Cristian
All browsers cache scripts, always do a hard refresh. `ctrl+F5`...
Alexander
+1  A: 

.width() should always return the size in pixels as an integer, even when the css property is set to auto.

Mike
Thanks, that way works perfect.
Cristian