Will jQuery ever return a CSS dimension in anything other than px?

I am rewriting my Textarea line count plugin (<- a shameless plugin) and asks this question:

When I call $("#someElement").css("letter-spacing") , will I ever get the value in em s or something other than px ? Based on this example: http://jsfiddle.net/xhhr2/ , at least in Google Chrome, it looks like either jQuery or the browser will convert the measurement to px for me. Can I always expect this behavior?

+7
source share
2 answers

According to We get a fresh answer that refers to Dean Edwards hack, jQuery goes through longer lengths to return the actual, calculated pixel value in all browsers, and not what was originally defined in the stylesheet, so it seems like yes, you you can rely on him.

+6
source

As far as I know, the browser should convert every size you give it (whether in em , % , etc.) in pixels. This is how the DOM saves it, and thus jQuery will return that value to you.

EDIT According to this answer here (which Pekka's answer refers to) only IE supports currentStyle , which gives the size (including the block) that CSS was set to. Apparently, no other browser supports this, instead they all use a computed style that converts everything to pixels. So I was about twice right: P

+5
source

All Articles