How do I get the width of text in pixels using JavaScript or jQuery?
I want to get the width of the textarea text. How do I get the width of the text in pixels?
I don't need the length of the text.
+3
user1241761
source
to share
1 answer
Just wrap the text in (invisible) span
and use jQuerys.width () to get the width.
Please note, you should not, like others, use div
it as it is a block element and depending on where / how you insert it, the block element can automatically expand to its full available width and give bad results.
+3
oezi
source
to share