Retrieving percentage CSS values (in firefox)

Loutleunsolve

New Member
I have a problem retrieving the exact css property value (in '%') on firefox. Suppose we have this extremely simple markup:\[code\]<div id="box">box</div>\[/code\]and this css:\[code\]#box{ width:200px; height:200px; left:10%; position:absolute; background:red;}\[/code\]and I'd like to retrieve the left position (in '%') by jsIt's obv very easy with mootools (demo -> http://jsfiddle.net/steweb/AWdzB/):\[code\]var left = $('box').getStyle('left');\[/code\]or jQuery (demo -> http://jsfiddle.net/steweb/RaVyU/):\[code\]var left = $('#box').css('left');\[/code\]or by plain js (demo -> http://jsfiddle.net/steweb/tUAKA/):\[code\]function getStyle(el,styleProp){ //from ppk's quirksmode var x = document.getElementById(el); if (x.currentStyle) var y = x.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); return y;}var left = getStyle('box','left');\[/code\]But if you try it on firefox (8.0.1) you'll see that the result is not correct (should be 10%, but it's 91px). The questions are: is there a bug on this newer version of firefox? Does anyone knows if it's a known bug? Am I doing something wrong?Thanks :)Update: I tried it also on older firefox releases, and it's not correct (it always returns px value).. for completeness, it works correctly on IE
 
Top