0

Simply, I'm trying to get the length of the text in the input in pixels (not the caret position).

I thought about creating a dummy input and putting the exact same value into it and measuring its width, but even if there is no width specified an input element is always constant width, and using a different element from an input could make the results inaccurate because of the existing styles.

soshimee_
  • 35
  • 1
  • 5
  • Consider using [`measureText`](//developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D/measureText) or [`contenteditable`](//developer.mozilla.org/en/docs/Web/HTML/Global_attributes/contenteditable). – Sebastian Simon Dec 25 '22 at 07:36

0 Answers0