How to change the content of a text area with JavaScript?

Sometimes, we want to change the content of a text area with JavaScript.

In this article, we’ll look at how to change the content of a text area with JavaScript.

How to change the content of a text area with JavaScript?

To change the content of a text area with JavaScript, we can set the value property of it.

For instance, we write

document.getElementById('myTextarea').value = '';

to select the text area with ID myTextArea with getElementById.

And then we set its value property to an empty string to empty the text area.

The text area is something like

<textarea id="myTextarea">foobar</textarea>

Conclusion

To change the content of a text area with JavaScript, we can set the value property of it.