I'm rewritting my Textarea Line Count plugin (<-- shameless plug), and have this question:
When I call $("#someElement").css("letter-spacing")
, will I ever get a value in em
s, or anything other than px
? Based on this example: http://jsfiddle.net/xhhr2/, in Google Chrome at least, it appears that either jQuery or the browser is converting the measurement to px
for me. Can I always expect this behavior?
According to Crescent Fresh's answer that links to a hack by Dean Edwards, jQuery goes through great lengths to return the actual, computed pixel value across all browsers and not what was defined originally in the style sheet, so it seems that yes, you can rely on it.
As far as I know, the browser has to convert every size you give it (whether it's in em
, %
. etc) into pixels. That's how the DOM stores it, and thus jQuery will return that value to you.
EDIT
According to this answer here, (referenced by Pekka's answer) only IE supports the currentStyle
, which gives the size (including the unit) that was set by CSS. Apparently, no other browser supports this, instead they all use computed style
which converts everything into pixels. So I was about half-right. :P
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With