Alright, I've search the jQuery docs (needs somebody devoted to maintaining), I've searched SO, and I've searched Google. I can't find the answer to this question.
In Words
In the past, I remember jQuery working like this:
$('#myObj').width()
returns the computed width of #myObj
.
$('#myObj').css('width')
returns the width as it is entered into the CSS stylesheet.
Now, any jQuery package I use returns the exact same number no matter which method I use.
$('#myObj').width()
returns the computed width of #myObj
as an integer (float?).
$('#myObj').css('width')
returns the computed width of #myObj
as a string with px
on the end.
In Pseudocode
#myobject{
width: 14em;
height: 14em;
}
<div id="myobject">Has Text</div>
<script type="text/javascript">
$( '#myobject' ).click(function(){
alert($(this).css('width') + "\n" + $(this).width());
});
</script>
//Always alerts "224px [newline] 224"
//Expected to alert "14em [newline] 224"
These pixel-based return values are almost completely useless, as I need to do calculations based on what's actually in the CSS. For example, I want to do math on the left
position of an element, but I can't because it keeps returning pixel values, which are worthless in an em
-based design.
Is there any way to get the actual values out of the CSS in jQuery?
Is this a jQuery bug, or am I missing something?
Here's a jsfiddle: http://jsfiddle.net/yAnFL/1/.
Resolution
Apparently, this is the intended result.
I have decided to use this plugin to do conversions for me.
Taking away control of CSS seems like a poor choice in the jQuery design.