Given the following html example:
<div class="announcementInfoText"> <p class="copyToClipboard"> <a id="selectAll">Select All Text</a> </p> <textarea ID="description" class="announcementTextArea">This is some sample text that I want to be select to copy to the clipboard</textarea> </div>
you can select the text in the text box with the following jQuery:
$("#selectAll").click(function () { $(this).parents(".announcementInfoText").children("textarea").select(); });
Now that the text “This is some sample text that I want to select to copy to the clipboard” is selected, you can simply press Ctrl + C and the text will be copied to the clipboard.
source share