1function copyToClipboard(element) {
2 var $temp = $("<input>");
3 $("body").append($temp);
4 $temp.val($(element).html()).select();
5 document.execCommand("copy");
6 $temp.remove();
7}
1var copyTextarea = document.getElementById("someTextAreaToCopy");
2copyTextarea.select(); //select the text area
3document.execCommand("copy"); //copy to clipboard
1<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
2<p id="p1">P1: I am paragraph 1</p>
3<p id="p2">P2: I am a second paragraph</p>
4<button onclick="copyToClipboard('#p1')">Copy P1</button>
5<button onclick="copyToClipboard('#p2')">Copy P2</button>
6<br/><br/><input type="text" placeholder="Paste here for test" />