I'm trying to create a textarea that is not read-only (users can type), but they cannot select and drag.
All that I found either turns the textarea into readonly, or disables my ability to focus.
Appreciate any help.
The readonly attribute is a boolean attribute. When present, it specifies that a text area should be read-only. In a read-only text area, the content cannot be changed, but a user can tab to it, highlight it and copy content from it.
The <textarea> readonly attribute in HTML is used to specify that the textarea element is read-only. If the textarea is readonly, then it's content cannot be changed but can be copied and highlighted. It is a boolean attribute.
Place the cursor near the text you need to copy. Then press the Windows key + Q and drag the cursor. You should see a blue box that you can now highlight the text by dragging the cursor.
In jQuery 1.8, this can be done as follows:
$('textarea')
.attr('unselectable', 'on')
.css('-webkit-user-select', 'none')
.css('-moz-user-select', 'none')
.css("-ms-user-select","none")
.css("-o-user-select","none")
.css("user-select",'none')
.on('selectstart', false)
.on('mousedown', false);
or by just using css,
#yourtextarea
{
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
You can use the CSS style user-select: none;
to keep text from being selectable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With