When I use outerWidth()
in jQuery it gives me the full width of the block element which is usually the whole page width (if it is the only thing on that line). In the picture below the red line is the width that I get from outerWidth()
. The blue line is the width I am trying to find.
How do I find the width of the area the text is taking up in jQuery.
Asked
Active
Viewed 981 times
1

Johnston
- 20,196
- 18
- 72
- 121
-
Did you try `innerWidth` to see what that returns? – Jack Feb 03 '15 at 22:38
-
@JackPattishall Yes same thing. – Johnston Feb 03 '15 at 22:39
-
2You cannot unless you calculate the width with the help of font-size-based char-size. Wrap the text with a span and use the width of the span – Fuzzyma Feb 03 '15 at 22:43
1 Answers
2
So you are doing this:
.outerWidth
$('element').outerWidth();
Get the current computed width for the first element in the set of matched elements, including padding and border.
.innerWidth
$('element').innerWidth();
Get the current computed inner width (including padding but not border) for the first element in the set of matched elements or set the inner width of every matched element.
.width
$('element').width();
Get the current computed width for the first element in the set of matched elements or set the width of every matched element.
Best regards ;)
Hope this will explain it to you ;)