Javascript DOM HTML Textarea set width using CSS style

Introduction

Change the width of a text area using the style.width property:

document.getElementById("myTextarea").style.width = "500px";

Click the button to change the width of the text area.

View in separate window

<!DOCTYPE html>
<html>
<body>

<textarea id="myTextarea">
At java2s.com you will learn how to make a website. 
</textarea>
<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {//from w ww .ja  va 2 s  . c om
  document.getElementById("myTextarea").style.width = "500px";
}
</script>

</body>
</html>



PreviousNext

Related