Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery .css() returning 100% as 100px

<style>
.info{
        width:94%;
      }
</style>

Now doing like this using JQuery

$('.info').css('width');

returns 94px rather than the equivalent value in pixles (500px in my case.)

if i set the width in css as 105% , JQuery would return it as 105px .

The height and width of the parent container is 600px and 500px respectively.

like image 994
Mevin Babu Avatar asked Oct 26 '12 13:10

Mevin Babu


1 Answers

I think a possible cause is the container of the element being hidden at the moment you're trying to obtain the dimensions.

I had a similar situation with nested divs and tables.

See the following fiddle where I managed to reproduce the behavior:

http://jsfiddle.net/36yvb/

I still think it's a bug in jQuery returning a percentage as an integer number (without the % sign) when not being able to actually compute the dimensions of the element. Change the width of #another-cell (expressed in %) and see it return the same value without the % sign when the table is hidden.

like image 85
Simón Avatar answered Sep 21 '22 05:09

Simón