How to Highlight Text in Textarea on Click

This is great if we want our users to copy something from the textarea. It’s more comfortable to them, especially if the content inside Textarea is long, and they don’t know a keyboard shortcut for selecting all content.

We can do this in pure JS, even inside our Textarea tag.

Here’s the snippet:

<textarea onclick="this.select()">Lorem Ipsum</textarea>

Output (click on textarea):