3

I want to get textarea text width. How do I get text width in pixels?

I do not want the text length.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1241761
  • 135
  • 2
  • 2
  • 8

1 Answers1

6

Simply wrap the text in a (invisible) span and use jQuerys .width() to get the width.

Note that you should not, like others said, use a div as it's a block-element - and depending on where/how you insert that, a block-element may auto-expand to the full available width and give bad results.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
oezi
  • 51,017
  • 10
  • 98
  • 115