Getting the width of an element as a floating point in jQuery

tomy56

New Member
I've been looking all over for a way to get the width of an element where it isn't rounded. The reason for wanting this is that I have several elements floated left with display inline-block and I am trying to autosize the text within them so that they use up the entire width of the container div. I am doing it like this:[*]Pick a small text size such as 1[*]Make all of the text that size[*]Add up the width of all of the floated elements[*]If it is smaller than the width of the container, increment the font size by a small value[*]Repeat 2-4 until you reach the maximum sizeThe problem is that there is always space left over that isn't being used. I believe this is because when I increment the font size by small amounts (ie. 0.01) to get an accurate size. The widths of the elements don't change because it is rounding down. I can keep incrementing and they wont change until it decides to round up and then to total width is over the limit. Here is a JSFiddle showing what I'm talking about:http://jsfiddle.net/Pkws3/The javascript might be a bit confusing but basically to save time it starts with large increments of the fontsize and then as it reaches the target size it'll make the increments smaller to be more accurate.I've tried using:\[code\]$(this).width()parseFloat($(this).css("width"))window.getComputedStyle\[/code\]But none of them seem to work.
 
Back
Top