简体   繁体   中英

How to get text width inside textarea? (javascript/jquery)

Is it possible to get width of text inside a textarea element?

I don't want $('textarea').val().length per se, as it doesn't depend on font-size.

I would prefer the absolute width of the text inside.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM