Javascript DOM HTML Textarea Object create

Introduction

We can create a <textarea> element via the document.createElement() method:

var x = document.createElement("TEXTAREA");

Click the button to create a TEXTAREA element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from w w  w. j av  a 2s  .c om
  var x = document.createElement("TEXTAREA");
  var t = document.createTextNode("At java2s.com you will learn how to make a website.");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related