javascripttextareasetattribute

Textarea - problems setting attribute


I'm saving the innerHTML of a div that contains several form inputs including textarea, select and textbox.

I'm setting the attributes for all elements using the onkeyup or onchange handler and the textbox and selected option get stored and returned but not the textarea. Setting the textarea attribute ie: ta.setattribute('value',this.value) adds a new "value" attribute to the tag that stores the text but doesn't populate the textarea. Also, when viewing the textarea in the console I don't see any content in the textarea but do see the content in a value property.

<textarea id="ta" value="some text"></textarea>

Any idea how set the textarea attribute so it returns content to the textarea instead of creating and populating the value attribute? TIA.


Solution

  • You can use innerText:

    const ta = document.getElementById("ta");
    ta.innerText = "THIS IS A TEST";
    <textarea id="ta"></textarea>