Textarea cols Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

The cols property sets or gets the cols attribute of a text area, which controls the visible width of a text area, in characters.

Set the cols property with the following Values

Value Description
number Sets the width of the text area. Default is 20

Return Value

A Number, representing the width of the text area, in characters

The following code shows how to change the width of a text area:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<textarea id="myTextarea" rows="4" cols="50">
new value/*w w  w  . ja  v a2s  .co m*/
</textarea>

<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {
    document.getElementById("myTextarea").cols = "100";
}
</script>

</body>
</html>

Related Tutorials