r/JavaScriptTips • u/[deleted] • Jun 22 '23
How to Set Value of Textarea in JavaScript
Textarea tags allows users to input and edit larger blocks of text. Users can enter large types of datas text, such as comments, descriptions, or messages. In this guide, we will explore how to change the value of a textarea element using JavaScript.
HTML:
<textarea id="myTextarea">HELLO</textarea>JS:
//Selecting textarea tag by ID
var textareaElement = document.getElementById("myTextarea");
//Setting the value in textarea
textareaElement.innerText = "This is the new text.";We can set the value for textarea tag by using the value, innerHTML, or innerText properties dynamically.
Reac more>> 3 ways set textarea value in JS dynamically
3
Upvotes