Hi jQuerians,

I ran into a bit of an odd problem this morning: $.css returns values in 
whatever units they 
were set with in the stylesheet (Safari and Firefox both return values in px 
regardless of how 
they were defined).

For example:
<p style="font-size: 12px; letter-spacing: 1em">Testing, Testing, 123...</p>

In Safari and Firefox, $('p').css('letter-spacing') returns the string '12px'. 
But in Opera, it 
returns '1em', which isn't useful for calculating anything.

As a workaround, I'm inserting an element:
<div style="position: absolute; visibility: hidden; width: 1em;">x</div>

Then measuring it:
var one_em = $('div').width();

Then fixing non-px values:
var px = parseFloat($('p').css('letter-spacing')) * one_em + 'px';

Is there a better way of getting pixel values fox css properties in Opera?


Thanks,
Luke

-- 
zinc Roe Design
www.zincroe.com
(647) 477-6016

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to