How to get the text width of a textarea tag?

Asked

Viewed 30 times

0

If in the code below the font was monospace and each character was 10px wide, the output would be 330px, the font size and type interfere with this value.

<textarea>fonte monospace com 33 caracteres</textarea>
  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of it. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English (short version). If the solution is very simple it is still possible for someone to do so in the comments.

  • I can’t put a span tag inside a textarea tag. If you put the textarea inside the span tag it will take the width of the input and not only the text.

  • Is that a question or a statement? Remember that in Portuguese (and several other languages), a question ends with the sign of "?".

  • See if it helps https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.