Textarea readOnly attribute
Definition and usage
readOnly
Attribute to set or return whether the text area content should be read-only.
In a read-only text area, content cannot be changed, but users can use the Tab key to switch to the area, or highlight and copy content from it.
This attribute reflects the HTML readonly attribute.
Tip:To prevent users from interacting with the text area, use disabled Attribute.
Example
Example 1
Set text area to read-only:
document.getElementById("myTextarea").readOnly = true;
Example 2
Check if the text area is read-only:
var x = document.getElementById("myTextarea").readOnly;
Syntax
Return readOnly attribute:
textareaObject.readOnly
Set readOnly attribute:
textareaObject.readOnly = true|false
Attribute Value
Value | Description |
---|---|
true|false |
Specifies whether the text area should be read-only
|
Technical Details
Return value: | Boolean value, returns if the text area is read-only true ; Otherwise return false . |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |