HTML DOM TextareaObject


Textarea Object

The Textarea object represents a text area (textarea) in an HTML form.

Every <textarea> tag in an HTML form can create a Textarea object.

For HTML textarea content, please refer to:HTML <textarea> tag.

You can access a Textarea object by indexing the elements array of the corresponding form, or by using the getElementById() method.

Examples

Get the text content of a textarea:

var x = document.getElementById("myTextarea").value;

Try it Yourself »

Tip:You can also find the <textarea> in the form's collectionelementsto get the content of the textarea.


Creating a Textarea Object

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

Example

Create a textarea element:

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

Try it Yourself »

Textarea Object Properties.

Property Description W3C
autofocus Sets or returns whether the textarea automatically gets focus. Yes
cols Sets or returns the width of the textarea. Yes
defaultValue Sets or returns the initial content of the text area. Yes
disabled Sets or returns whether the textarea should be disabled. Yes
form Returns a reference to the form object that contains the textarea. Yes
maxLength Sets the maximum number of characters that can be entered in the textarea element. Yes
name Sets or returns the name of the textarea. Yes
placeholder Sets or returns the value of the placeholder attribute. Yes
readOnly Sets or returns whether the textarea should be read-only. Yes
require Sets or returns whether the textarea is required to have content. Yes
rows Sets or returns the height of the textarea. Yes
type Returns the form type of the text area. Yes
value Sets or returns the text within the textarea. Yes

Textarea Object Methods

Method Description W3C
select() Selects the text in a textarea. Yes

Standard Properties and Events

The Textarea object also supports standardattributesandevents。

Other Extensions