'How to set the textarea value in JavaScript

I have the following JavaScript code:

var c=document.createElement("textarea");
c.value="what ever";
document.body.appendChild(c);

This supposed to add a textarea tag at the end of my page. The textarea is added, but it doesn't have the value set.

How can I solve that?

Enter image description here



Solution 1:[1]

Use innerHTML to set the value of textarea.

var c=document.createElement("textarea");
c.innerHTML="what ever";
document.body.appendChild(c);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Derek Wang