Javascript DOM HTML Textarea cols Property set

Introduction

Change the width of a text area:

document.getElementById("myTextarea").cols = "100";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*w  w w. j av  a 2  s .c  o m*/
  document.getElementById("myTextarea").cols = "100";
}
</script>

</body>
</html>

The cols property sets or gets the value of the cols attribute of a text area.

The cols attribute sets the visible width of a text area in characters.

Value Description
number Specifies the width of the text area (in average character width). Default is 20
Return Value A Number, representing the width of the text area, in characters



PreviousNext

Related