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?
views:
42answers:
1
+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
2010-10-17 12:55:52
Nice workaround! I wait for some other ansers before accept it
framomo86
2010-10-17 13:02:17
@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
2010-10-17 15:20:13