Categories
JavaScript Answers

How to count text area characters with JavaScript?

Spread the love

To count text area characters with JavaScript, we use the value property.

For instance, we write

document.getElementById("textarea").onkeyup = (e) => {
  console.log(e.target.value.length);
};

to select the text area with getElementById.

And then we set its onkeyup property to a function that logs the number of characters entered into the text area.

e.target.value has the input value string.

length has the number of characters.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.