Skip to content

Instantly share code, notes, and snippets.

@synackme
Created February 28, 2014 04:49
Show Gist options
  • Save synackme/9265441 to your computer and use it in GitHub Desktop.
Save synackme/9265441 to your computer and use it in GitHub Desktop.
copy
Given the following example html:
<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 within the textarea 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 be select to copy to the clipboard" is selected, you can simply hit Ctrl+C and the text is copied to the clipboard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment