views:

42

answers:

1

It is possible to get text width inside a textarea element. I don't care of its length$('textarea').val().length This cose doesn't care of font-size. I would prefer the absolute width of the text inside. It is possible?

+3  A: 

It's well possible this information is impossible to get hold of.

Workaround idea:

  • Create a span element with the font size settings of the textarea
  • Give the span element the input's value using .text(value)
  • Measure the span's width
Pekka
Nice workaround! I wait for some other ansers before accept it
framomo86
@framomo86: If I can remember well, this was Facebook's approach to auto-resize the textarea accordingly to the size of the text. But instead of `span` I guess a `pre` element is better, it would jump lines with `\n` and wouldn't need a `<br>`.
BrunoLM